Upload Validation
File fields validate in two phases.
Upload-time rules come from file-specific methods such as image(), maxSize(), accept(), and dimensions(). They run while Laravel has access to a real uploaded file:
use InertiaUI\Forms\Fields\File;
File::make('avatar')
->image()
->maxSize(2048)
->maxDimensions(width: 1000, height: 1000);Submit-time rules such as required() run when the form is submitted:
File::make('avatar')
->required()
->image()
->maxSize(2048);A submitted temporary token strips the file-specific rules from submit-time validation, because the submitted input contains an encrypted string. To get the resolved SubmittedUpload in controller code, use the Form upload and uploads helpers, or the request-level formUpload and orderedFormUploads macros.
Managed package uploads also bind the upload validation profile to the returned temporary token. Form validation rejects an unvalidated temporary token submitted to a managed field with upload rules.
Chunked and direct-to-storage uploads check the declared file size against rules such as maxSize() before the upload starts. The completed file is still validated. For S3 uploads, this happens after the file reaches storage.
The token guard is automatic for the built-in temporary route, chunked uploads, and direct-to-storage uploads. A custom temporaryUploadUrl() has no package token guard by default, because its response may be an application-owned path, url, or id. Use requireValidatedUploads(true) only for a custom endpoint that returns compatible Inertia Forms tokens. To disable the guard explicitly, pass false.
Upload Validators
The validateUploadsUsing method adds upload-time validation that doesn't fit Laravel's built-in file rules, such as malware scans, content validation, or tenant policy:
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Validation\ValidationException;
use InertiaUI\Forms\Fields\File;
use InertiaUI\Forms\FileUploads\Contracts\ValidatesFileUploads;
use InertiaUI\Forms\FileUploads\TemporaryUpload;
use InertiaUI\Forms\FileUploads\UploadRules;
class EnsureArchiveIsSafe implements ValidatesFileUploads
{
public function validate(
TemporaryUpload $upload,
UploadedFile $file,
UploadRules $rules,
Request $request,
): void {
if ($file->getClientOriginalExtension() !== 'zip') {
return;
}
// Run your scanner here...
$blocked = false;
if ($blocked) {
throw ValidationException::withMessages([
'file' => ['The archive failed the security scan.'],
]);
}
}
}
File::make('archive')
->directToStorage('s3')
->maxSize(1024 * 1024)
->validateUploadsUsing(EnsureArchiveIsSafe::class);Upload validators run after the completed object is available and before the encrypted temporary token is returned to the browser. To return a normal 422 upload error and clean up the rejected temporary object, throw a ValidationException.
For direct-to-storage uploads, Laravel streams a remote S3 or MinIO object to a temporary local file only when Laravel file rules or custom validators need to read the completed bytes. A disk-only upload profile still binds the request to the intended disk without reading the object again through PHP.