F
Filament4w ago
Akki

multi file upload with total size limit

Hello team I am trying to limit a user to allow multiple file uploads, which is working, but I also want to set an overall limit of 20mb. Let's say Case 1 : upload 4 files each of 5mb ( ✅ ) Case 2: upload 1 file of 20 mb ( ✅ ) Case 3: upload 3 files of 10 mb ( ❌ ) Case 4: upload 1 file of 21 or more mb ( ❌ ) I am using laravel 11.31, Livewire 3.0 and filament 3.2 Do help if if you have any solution for this.
4 Replies
Dhru
Dhru4w ago
For case 1,2,4 can use built in limits For case 3 use method Overall will look something like this in the end FileUpload::make('attachments') ->label('Upload Files') ->multiple() ->maxSize(20000) ->rules([ function ($attribute, $value, $fail) { $totalSize = array_reduce($value, function ($carry, $file) { return $carry + $file->getSize(); }, 0); if ($totalSize > 20000 ) { $fail('The total size of all files must not exceed 20MB.'); } }, ]) ->disk('local') ->directory('uploads');
Akki
AkkiOP4w ago
Thanks for the quick response but this is not working on my way end.
Dhru
Dhru4w ago
try playind around with the rules method i didn't test it
Akki
AkkiOP4w ago
Sure, I'll work on it further, but if you get some time, then try to run on your end.
No description

Did you find this page helpful?