mdecooman's avatar

Getting the correct mimetypes when uploading files

uploading file get the wrong mimetypes.

Coreldraw files cdr are recognised as application/zip
Illustrator ai is recognised as pdf

so basically I need to put in my validation rules:

//application/postscript is useless in this case

'file' => 'required|file|mimetypes:application/zip,application/pdf

Anyone could point me to the right direction?

Thanks

0 likes
4 replies
tykus's avatar

Try using the file extensions only:

'file' => 'required|file|mimetypes:cdr,ai
mdecooman's avatar

Hi @tykus

Thanks for your answer. I guess you meant 'mimes' but the content-type is still checked (expected behaviour). A CorelDraw file, for example, is not recognized and therefore Laravel/Symfony falls back to an application/octet-stream type.

Putting application/octet-stream in the rule would defeat the purpose. Editing the nginx mime.types and restarting it doesn't change anything.

Building custom validation based on, ie, this: http://pastebin.com/raw/NcL5BLwg seems an overkill. I can't believe this trivial requirement has not been met somehow.

PS: the fact that some ai file are recognised as pdf can be normal (depending on how you save your ai file) The problem still remains for other files like from CorelDraw.

robrogers3's avatar

well

a) you could be gross and use a regex (nasty)

b) well creating a custom validator is not that bad, then just leverage that class. in your validator.

in 5.5 there is an artisan command to make a rule (for validation) but its' not tricky to do it manually. let me know if you want some boiler plate directions.

ps. really it's not hard at all

mdecooman's avatar

Hi @robrogers3,

Thank you for your answer. No issues extending validation in L55 but I do search for another solution.

I believe it is more the responsibility of the (UNIX) host to deal with this instead of tweaking the code for each case. In this example a CDR file has an existing standard like Adobe has for most of its files. I don't want to maintain my own versions when it can be dealt otherwise.

Laravel/Symfony registers 2 guessers by default: FileBinaryMimeTypeGuesser and FileinfoMimeTypeGuesser. They both implement the MimeTypeGuesserInterface. The choice then is to either re register the one I prefer and customize it or create a new one.

Digging further...

Please or to participate in this conversation.