Skip to content

Chunked Uploads ​

The chunked method sends large files through your Laravel application without depending on one huge request:

php
use InertiaUI\Forms\Fields\File;

File::make('video')
    ->chunked(size: 2 * 1024 * 1024); // bytes

The built-in controls pause, resume, cancel, and retry uploads, and show progress for each file. Interrupted uploads retry automatically and wait while the browser is offline. Resuming works while the page stays open, but uploads don't survive a page reload.

The default chunk size is 5 MB. The size option may not exceed file_uploads.temporary_uploads.chunked.size. See Chunked Temporary Uploads for the server settings.

Uploads are also checked for corruption where the browser supports it, which normally means over HTTPS. These checks support up to 100,000 chunks per file. With very small chunks, make sure your largest file stays within that limit, or it will fail at completion.

Chunked uploads are the right fit for local 1-2 GB uploads where PHP still receives the bytes.

Completion Hook ​

A completion hook stores or processes a chunked upload as soon as it finishes. Register a class that implements HandlesCompletedUploads on the upload route group:

php
use App\Uploads\StoreUpload;
use Illuminate\Support\Facades\Route;

Route::inertiaFormUploads('media-uploads', ['web', 'auth'], 'media-uploads', [
    'rules' => ['image', 'max:5120'],
    'complete' => StoreUpload::class,
]);

The hook receives the validated file with its original name, detected mimeType, size, sha256, and validated metadata:

php
namespace App\Uploads;

use Illuminate\Http\Request;
use InertiaUI\Forms\FileUploads\CompletedUpload;
use InertiaUI\Forms\FileUploads\Contracts\HandlesCompletedUploads;
use RuntimeException;

class StoreUpload implements HandlesCompletedUploads
{
    public function handle(CompletedUpload $upload, Request $request): ?array
    {
        $path = $upload->store('media', 'public');

        if ($path === false) {
            throw new RuntimeException('Unable to store the upload.');
        }

        return ['path' => $path];
    }
}

A retried completion reuses the successful response. Any exception other than a ValidationException restores the files moved through store or storeAs, so completion may retry. Make your own database writes and other side effects safe to repeat. The $upload->file->getIdentifier() method provides a stable key for upserts. To reject the upload without a retry and delete its file, throw a ValidationException.

The store and storeAs methods take ownership of the file and return false if the destination already exists. After they succeed, cleanup leaves the file alone, and the returned key represents an existing file that retains the upload's validation rules. Without either call, the file remains a temporary upload. Use the field's upload rules token for an upload whose key you will submit to a form. For Media Library fields, leave storage to the form.

After awaiting the upload, read the hook's returned data from task.result. The task still resolves to its key:

ts
const { uploadFile } = useChunkedFileUploader()
const task = uploadFile(file, { url: '', chunkedUrls, uploadRulesToken })
const key = await task
const { path } = task.result as { path: string }

FileUpload also exposes the result on each file item, and through Vue's @upload-complete event or React's onUploadComplete callback. The callback receives id, name, size, type, submittedValue, and result.

Headless uploads may pass metadata in their upload options. Only the fields validated by the group's metadata rules reach the hook. File fields don't send metadata, so their upload groups shouldn't require it.

Testing Uploads ​

The UploadsFormFiles trait uploads a file through a group's chunked routes. It returns the completion response, or the first failed response:

php
use App\Models\User;
use Illuminate\Http\UploadedFile;
use InertiaUI\Forms\Testing\UploadsFormFiles;

uses(UploadsFormFiles::class);

test('photos are stored on completion', function () {
    $user = User::factory()->create();
    $file = UploadedFile::fake()->image('photo.jpg');

    $this->actingAs($user)
        ->uploadFormFileInChunks($file, routes: 'media-uploads')
        ->assertOk()
        ->assertJsonPath('result.path', fn (string $path) => str_starts_with($path, 'media/'));
});

Pass parameters for the group's route parameters, metadata for your application's fields, and uploadRules for a field's upload rules token. You may also pass a chunkSize.

For large upload testing, keep normal CI focused on representative multipart uploads. The demo browser suite uses a live MinIO multipart upload that is large enough to exercise multipart behavior, without making every pull request move gigabytes of data. Reserve 1-2 GB upload tests for manual or scheduled infrastructure smoke runs.