linktoahref's avatar

Laravel Validate Array of Files Max Size

My View has an array of file inputs like

<input type="file" name="videos[]" />
<input type="file" name="videos[]" />
...
...

and I want to validate for the total allowable upload size (Eg: Total Allowable Upload limit is 3Mb). I've written the validation like

$validatedData = $request->validate([
     'videos.*' => 'present|file|mimetypes:video/mp4,video/ogg|max:3000',
]);

but this validates 3Mb per video.

I've tried

$validatedData = $request->validate([
     'videos' => 'file|max:3000',
]);

but the validation is not working. Do I have to write a Custom Validation Rule to validate the total uploaded file size limit. Or is there any predefined validation rule? Any help appreciated.

Thank You!

0 likes
5 replies
newbie360's avatar

i don't know if this work

$validatedData = $request->validate([
     'videos.*' => 'present|file|mimetypes:video/mp4,video/ogg|max:3000',
     'videos' => 'file|max:3000'
]);
lara28580's avatar

Would be interested in that too! Is there a solution for that now?

corndoglet's avatar

Tried this solution of extending Validator with a custom rule and it worked!

Be sure to includeuse Illuminate\Support\Facades\Validator at the top of your AppServiceProvider.

2 likes

Please or to participate in this conversation.