Livewire FileUpload Issue

I am trying to upload a file with livewire trait already added everything working fine…but the problem is when i select a file wire:model send a request to make temp url for livewire if the file size is high that request took too long to complete then if the user click submit bcz at that time livewire didnt create any temp url mean no file it says field is required mean validation run…what i want to do is to validate as soon as user select file before livewire send request for temp url…so is there any solution for it…
on local as soon as i select file it send request if its large it shows

The content may not be greater than 12288 kilobytes.

Dont know from where does this msg come from but its not showing in live site i am using LAMP on Digital ocean

public $content;

public function updatedContent()
{
    $this->validate([
        'content' => 'required|max:2048',
    ]);
}

submitFunction()

$this->validate(['content' => 'required|max:2048',],$customMessages);

The size of this file was 3MB.


livewire v-1.3

have you seen File Uploads section in the docs?

yes did i miss something?

If the app is timing out before the upload is complete, there would be no file to validate. It won’t matter what you set your validation points at as the request would only validate once it has the file on its side.

Meaning, just because you say “I only want files that are 2MB” doesn’t mean your app would reject a file at the browser level. The app needs access to the file before it can determine whether the file meets size criteria. That means upload has to be successful before you can validate.

yes thats the problem…in normal laravel app laravel do not upload the file to storage/tmp folder it only upload the file when we submit the form…but in livewire when we select a file wire:mode start uploading the file to server in tmp directory then validate that file…and that uploading to server for tmp url is taking too long…

By default, Livewire will validate ALL temporary file uploads with the following rules: file|max:12288and i have to add a new rule in the config. https://laravel-livewire.com/docs/file-uploads#configuration

2 Likes