Skip to content

Upload Routes ​

Register the upload routes in your routes/web.php file:

php
use Illuminate\Support\Facades\Route;

Route::inertiaFormUploads();

By default, this registers the built-in endpoints under /_inertia-forms. You usually don't need to call these routes yourself, because the frontend field reads the route URLs from the serialized field configuration.

Temporary uploads use two endpoints with the default route name prefix:

  • POST /_inertia-forms/file-upload (inertia-forms.file-upload.store) stores a selected file and returns an encrypted temporary upload token.
  • DELETE /_inertia-forms/file-upload (inertia-forms.file-upload.destroy) removes an unused temporary upload.

Chunked uploads add a small route group below /_inertia-forms/file-upload/chunked:

  • start creates a pending upload.
  • status checks which bytes have already been received.
  • chunk appends the next chunk.
  • complete turns the uploaded chunks into a temporary upload token.
  • abort cancels the pending upload.

Direct-to-storage uploads add a route group below /_inertia-forms/file-upload/direct:

  • start creates a signed single-object or multipart upload.
  • object receives local test-driver PUT uploads.
  • part signs or receives individual multipart parts.
  • status checks the parts already uploaded.
  • complete validates the stored object and returns a temporary upload token.
  • abort cancels an unfinished upload.

Customizing Routes ​

You may customize the prefix and middleware:

php
Route::inertiaFormUploads(
    prefix: '/uploads',
    middleware: ['web', 'auth', 'throttle:60,1'],
);

To give a separate section of your application its own endpoints, register another route group with its own route name prefix:

php
Route::prefix('admin')
    ->name('admin.')
    ->group(function () {
        Route::inertiaFormUploads(
            prefix: '/backoffice/_inertia-forms',
            middleware: ['web', 'auth', 'can:access-admin'],
            name: 'backoffice',
        );
    });

The uploadRoutes method points a field at that route group. The selected group supplies the field's temporary, delete, chunked, and direct-to-storage endpoints:

php
use InertiaUI\Forms\Fields\File;

File::make('avatar')
    ->uploadRoutes('admin.backoffice');

Pass the full route name prefix, as Laravel composes it from the parent route groups and the upload route group's name.

A group's prefix may have parameters. Pass their values as the second argument:

php
Route::inertiaFormUploads('media-uploads/{auth}', ['web'], 'media-uploads');

File::make('photo')
    ->chunked()
    ->uploadRoutes('media-uploads', ['auth' => 'user']);

An upload stays in the group and under the parameter values it started with. Another group, or another {auth} value, rejects its upload ID.

A field's upload rules token is bound to its group once that group has rules, metadata, or a complete hook. The form then only accepts keys from that group's endpoints, so it rejects a file uploaded through a less strict group. A chunked field of a group with a completion hook only accepts keys from the group's chunked endpoints, since only they run the hook.

Route Group Options ​

The fourth argument of Route::inertiaFormUploads() configures one group:

OptionMeaning
rulesFile validation rules applied to every transport. Use string rules.
max_sizeMaximum chunked upload size in kilobytes. Overrides the global limit.
lifetimeLifetime of a chunked upload and its key in seconds, including cleanup.
chunk_sizeMaximum chunk size in bytes. Fields using this group inherit it.
metadataValidation rules for metadata sent at the start of a chunked upload.
completeA class implementing HandlesCompletedUploads. See Completion Hook.

Size limits are checked before the upload starts. File types and other rules are checked against the received contents.

php
Route::inertiaFormUploads('imports', ['web', 'auth'], 'imports', [
    'rules' => ['mimetypes:text/csv,text/plain'],
    'max_size' => 8 * 1024 * 1024, // 8 GB
    'lifetime' => 6 * 3600,
]);

Serialized Upload Configuration ​

The PHP upload methods serialize to the same public props that the standalone Vue and React controls accept. Generated fields fill in the route URLs and the validation token automatically. Standalone controls must provide the values their chosen transport requires.

PropMeaning
storeWithFormKeep native browser File objects for the final multipart form request. It bypasses temporary, chunked, and direct uploaders.
temporaryUploadUrlRegular multipart upload endpoint. The request field is file, and the response may supply the submitted value as key, path, url, or id.
temporaryUploadDeleteUrlOptional delete endpoint used to discard a completed temporary upload that the user removes.
chunked / chunkSizeEnable same-origin chunking and set bytes per append request, up to the chunk size the start endpoint returns.
chunkedUrlsEndpoints named start, status, append, complete, and abort. All are required for standalone chunked uploads.
concurrentUploadsMaximum number of this field's files that upload at the same time. Defaults to 3. Other files wait in a queue.
directToStorage / uploadDiskEnable direct upload and identify the Laravel filesystem disk bound to the signing endpoint.
uploadPartSize / uploadMultipartThresholdSet multipart part bytes and the byte threshold above which direct uploads become multipart.
directUploadUrlsEndpoints named start, signPart, status, complete, and abort. All are required for standalone direct uploads.
uploadRulesTokenEncrypted package upload profile sent with managed upload requests. It carries upload validation rules and binds built-in direct-to-storage requests to their intended disk. Applications normally obtain it from serialized PHP props.
requiresUploadRulesTokenRequire the completed temporary token to prove it used the expected validation profile in the final request.

The FileUpload field also accepts existingFiles as an explicit initial list. A non-empty list takes precedence over the existing-file objects in the initial bound value. Composer applies the same transport props to its attachments. RichText nests them under imageUploads and never supports storeWithForm.