Reputation: 458
Frustrating one here: I am validating a file upload in my Laravel application, and here is my line that is throwing errors (I literally copy-pasted this off of StackOverflow and double checked that it was right on the Laravel docs):
'video_file' => 'mimetypes:video/avi,video/mpeg,video/quicktime'
Now, what you're probably thinking is, "Ok, so are you uploading one of those types? Are you SURE?".
Yup.
I took the validation run off, uploaded the same video file, and ran this code to check what the MIME type was:
$files = $request->file('video_file');
foreach($files as $file) {
file_get_contents($file);
return $file->getMimeType();
}
Wanna know what it returned?
video/quicktime
So, how should I validate that someone is uploading a video file? To be honest, at this point, I really have no need to validate each video type, I just need to make sure it is A VIDEO. Doesn't matter if it is .mov, .mp4, .avi, whatever.
Keep in mind this is a 'multiple' input for the file upload, so while that may have something to do with it, I don't think so because I took that off and it still didn't go through.
Any thoughts?
Upvotes: 0
Views: 743
Reputation: 3226
When validating arrays you are better of with this.
For example:
'video_files' => 'array',
'video_files.*' => 'mimetypes:video/avi,video/mpeg,video/quicktime',
As you can see I would also suggest using a plural key when handeling an array, but that is personal taste.
Upvotes: 1