jmjl161100/laravel-chunk-upload

Laravel chunk upload support package.

v1.0.0 2025-04-18 07:04 UTC

This package is auto-updated.

Last update: 2025-04-18 07:16:28 UTC


README

License PHP Version Laravel Version

Laravel Chunk Upload

Laravel package for handling chunked file uploads with multi-driver support (Local, Qiniu, etc.).

Features

  • ✅ Chunked file upload support
  • ✅ Multiple storage drivers (Local, Qiniu Cloud)
  • ✅ Progress tracking
  • ✅ Automatic chunk merging
  • ✅ Laravel 11.x compatibility

Installation

  1. Install via Composer:
    composer require jmjl161100/laravel-chunk-upload
    

Configuration

Add a new disk to your config/filesystems.php config:

<?php

return [
   'disks' => [
        //...
        'qiniu' => [
           'driver'     => 'qiniu',
           'access_key' => env('QINIU_ACCESS_KEY', 'xxxxxxxxxxxxxxxx'),
           'secret_key' => env('QINIU_SECRET_KEY', 'xxxxxxxxxxxxxxxx'),
           'bucket'     => env('QINIU_BUCKET', 'test'),
           'domain'     => env('QINIU_DOMAIN', 'xxx.clouddn.com'), // or host: https://xxxx.clouddn.com
        ],
        //...
    ]
];

Usage

Basic Upload

use Jmjl161100\ChunkUpload\Facades\CheckUpload;

// initialization
$rt = CheckUpload::init($fileName);

// Upload data in chunks
$rt = CheckUpload::uploadPart($uploadId, $partNumber, $file);

// Complete file upload
$rt = CheckUpload::complete($uploadId, $partList);

Frontend Integration

JavaScript example (using Axios):

async function uploadFile(file) {
    const chunkSize = 5 * 1024 * 1024; // 5MB
    const totalChunks = Math.ceil(file.size / chunkSize);

    for (let i = 0; i < totalChunks; i++) {
        const chunk = file.slice(i * chunkSize, (i + 1) * chunkSize);
        await axios.post('/upload-chunk', {
            file_id: file.name,
            chunk: chunk,
            index: i
        });
    }

    await axios.post('/complete-upload', {file_id: file.name});
}

Drivers

Supported Drivers

  1. Local Driver

    • Chunk Storage: Chunks under the disk root configuration
    • Final Files: Disk root configuration
  2. Qiniu

    • Requires qiniu/php-sdk package
    • Direct upload to Qiniu Cloud Storage

Security

If you discover any security issues, please email author instead of creating an issue.

License

MIT License (see LICENSE)