Handling Submitted Uploads
Temporary, chunked, and direct-to-storage uploads submit encrypted tokens instead of files. This page covers how your controller reads those uploads and stores them.
Reading Submitted Uploads
Temporary upload handling doesn't replace the values of $request->input() or $request->all() with raw UploadedFile instances. The submitted input still contains the encrypted keys, while the resolved uploads are stored separately on the request.
After validation, use the Form helpers to read submitted uploads. The upload method returns one SubmittedUpload, and the uploads method returns the ordered collection for a multiple field. Use validated(files: false) for model attributes, so encrypted temporary upload strings are never persisted by accident:
namespace App\Http\Controllers;
use App\Forms\ProfileForm;
use App\Models\Profile;
use InertiaUI\Forms\FileUploads\SubmittedUpload;
use InertiaUI\Forms\Validate;
class ProfileController extends Controller
{
public function update(#[Validate] ProfileForm $form, Profile $profile)
{
$profile->update($form->validated(files: false));
$avatar = $form->upload('avatar'); // ?SubmittedUpload
if ($avatar) {
$profile->forceFill([
'avatar_path' => $avatar->store('avatars', 'public'),
])->save();
}
$photoNames = $form->uploads('photos')
->map(fn (SubmittedUpload $photo) => $photo->getIdentifier());
}
}The store and storeAs methods move a staged upload on a local disk to a local target disk with a rename, so a large file isn't copied and doesn't take twice the space. Other target disks receive a copy, after which the staged file is deleted.
The request-level equivalents remain available. Use the formUpload method for one file and the orderedFormUploads method for an ordered collection:
// $request is the current Illuminate\Http\Request...
$avatar = $request->formUpload('avatar');
$photos = $request->orderedFormUploads('photos');Accessor Gating
The form and request upload accessors only return files the active form allows. They return null or an empty collection for unauthorized fields, hidden fields, and tokens uploaded under different field rules. The same gate applies before and after validate().
Once a form registers upload gates, unknown keys also fail closed. The request accessors remain ungated only while no form has registered upload context, such as in a standalone HasUploads FormRequest workflow.
Don't use $request->file('avatar') for default temporary uploads, chunked uploads, or direct-to-storage uploads. The final form request contains encrypted token strings for those fields, not native multipart files. Read them with $form->upload('avatar') or $request->formUpload('avatar') instead.
Eager Hydration
For eager hydration, implement the HasUploads marker contract on a FormRequest. The package reads that request's rules, discovers the file and temporary token paths, and hydrates the request when Laravel resolves it:
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use InertiaUI\Forms\Fields\File;
use InertiaUI\Forms\FileUploads\Contracts\HasUploads;
class StoreProfileRequest extends FormRequest implements HasUploads
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$avatar = File::make('avatar')->image()->nullable();
$photos = File::make('photos')->multiple()->image()->nullable();
return [
'avatar' => $avatar->getRules(),
...$avatar->getAdditionalRules(),
'photos' => $photos->getRules(),
...$photos->getAdditionalRules(),
];
}
}Storing Uploads
A SubmittedUpload may represent a new temporary upload, a direct-to-storage upload, or an existing file that stayed selected while editing. It offers the following methods:
isNewandisExistingtell the cases apart.getUploadedFilereturns a new local or remote upload.getRemoteFilereturns the direct-to-storage details.getExistingFilereturns a retained existing value.getIdentifierreturns a stable key for ordering.
Default server-side temporary uploads expose an InertiaUI\Forms\FileUploads\UploadedFile, which extends Laravel's uploaded file class. To persist a new upload, call the store method directly on the SubmittedUpload:
// $form is the validated form instance...
$path = $form->upload('avatar')?->store('avatars', 'public');The storeAs method stores the upload under the name you give it:
$path = $form->upload('avatar')?->storeAs('avatars', 'profile-photo.jpg', 'public');By default, both helpers remove the Inertia Forms temporary upload after it has been stored. To keep the temporary source, pass deleteTemporary: false as a named argument.
Direct-to-storage uploads expose a RemoteFile. The storage helpers may promote those objects on the same Laravel filesystem disk. With deleteTemporary: true, the object moves to its final path, and with deleteTemporary: false, it's copied. Passing a different disk throws an exception, because promoting an object across disks may hide unexpected storage cost. A direct-to-storage object you don't promote stays in its temporary inertia-forms-upload-* directory, which the cleanup command deletes once it expires, so don't persist its getRemoteFile()->getPath() as a permanent location.
Existing files can't be stored again, because there is no new upload to persist. Calling store or storeAs on one throws an exception.
Stored Filenames
The store method generates a random 40-character filename with an extension derived from the file contents. Local uploads use Laravel's hashName behavior. Direct-to-storage uploads inspect the start of the stored object without downloading the whole file. Unknown file types are stored without an extension.
The storeAs method uses the name you pass exactly as given, so you remain responsible for the extension it carries.