File-upload Csv Not Working
So I'm using File Upload in which I'm trying to do upload of csv file using syntax ->acceptedFileTypes(['application/csv']) But its's showing an error File type is invalid that its not Csv
18 Replies
Depending on what application the csv was saved out of it could be a different mime type. Look up the possible mime types for csv and add them all.
For example, Excel doesn’t have a application/csv mime type.
its saved from libre office
Still. It apparently has a different mime type. So you need to include all possible csv mime types in the field.
so what would be the right syntax for that and how can I validate it that if the file is no csv you cannot upload.......
Add
application/vnd.ms-excel
, text/csv
and text/plain
Also add
text/plain
what if someone is trying to upload image or video how can i validate it saying video and image cannot be uploaded
Could also be text/csv
Don't validate the negative
Saade mentioned that 😄
ok thanks everyone
My point still stands. Lol. More than one csv mime type.
Here, I'm using csv file to upload and it shows - The file Upload field must be a file of type: text/csv, application/csv........I mean I'm already using CSV . help!
Run your file through a mime type checker. See what the actual mime type is in the file.
how can I do that?
@awcodes
Google for an online checker.
ok
mime type is text/plain I was not using it in acceptedFileTypes
There you go. But you need to allow for all csv mime types. You never know what program your users will be using to create their csv’s from.
Yes absolutely right. Thank-you 🙂