Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

michaelkeegan's avatar

Livewire 3 - temporary_file_upload configuration not working

I'm trying to build an image uploader in Livewire 3 using these instructions - https://livewire.laravel.com/docs/uploads

I've edited the config/livewire.php file to change the location where the temporary file upload is saved and I've also added some validation rules as follows -

'temporary_file_upload' => [
        'disk' => 's3',        // Example: 'local', 's3'              | Default: 'default'
        'rules' => ['required', 'image', 'max:1024', 'mimes:jpg,jpeg'],       // Example: ['file', 'mimes:png,jpg']  | Default: ['required', 'file', 'max:12288'] (12MB)
        'directory' => 'tmp',   // Example: 'tmp'                      | Default: 'livewire-tmp'
        'middleware' => 'throttle:5,1',  // Example: 'throttle:5,1'             | Default: 'throttle:60,1'
        'preview_mimes' => [   // Supported file types for temporary pre-signed file URLs...
            'jpg', 'jpeg'
        ],
        'max_upload_time' => 5, // Max duration (in minutes) before an upload is invalidated...
    ],

The disk configuration is working successfully but the rules are being ignored. I can upload a 5MB png file, or a PDF or a MP4 file with no indication that something is wrong - i.e. the file is saved to the tmp directory. I understand that it has to upload the file before it can validate it but I don't understand how, or if, I can access the validation error message.

0 likes
3 replies
LaryAI's avatar
Level 58

It seems like you've configured the temporary_file_upload correctly in your config/livewire.php. However, to enforce the validation rules and handle the error messages, you need to make sure that you're using the validation within your Livewire component's file upload method.

Here's an example of how you might handle file uploads and validation in your Livewire component:

use Livewire\Component;
use Livewire\WithFileUploads;

class ImageUploader extends Component
{
    use WithFileUploads;

    public $photo;

    public function updatedPhoto()
    {
        $this->validate([
            'photo' => $this->temporary_file_upload['rules'], // Use the rules from the config
        ]);
    }

    public function save()
    {
        // Save logic goes here
    }

    public function render()
    {
        return view('livewire.image-uploader');
    }
}

In your Blade template, you should also make sure to display the error messages for the user to see. Here's an example of how you might do that:

<div>
    <input type="file" wire:model="photo">

    @error('photo') <span class="error">{{ $message }}</span> @enderror

    <button wire:click="save">Save Photo</button>
</div>

When you use wire:model with a file input, Livewire will automatically upload the file to the temporary directory and run validation rules against it. If the validation fails, Livewire will populate the $errors variable with the appropriate messages, which you can then display in your Blade template using the @error directive.

Make sure that you're using the updated{PropertyName} method to validate the file right after it's been updated. This method is automatically called by Livewire when the specified property changes.

If you follow this pattern, you should be able to enforce the validation rules and provide feedback to the user when a file does not meet the specified criteria.

michaelkeegan's avatar

@LaryAI this gives me the error - Property [$temporary_file_upload] not found on component: [image-uploader]

MouteeSabouni's avatar

Hello, Michael, can you please share your Livewire component code?

Please or to participate in this conversation.