F
Filament2y ago
Noor

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
awcodes
awcodes2y ago
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.
Noor
NoorOP2y ago
its saved from libre office
awcodes
awcodes2y ago
Still. It apparently has a different mime type. So you need to include all possible csv mime types in the field.
Noor
NoorOP2y ago
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.......
Saade
Saade2y ago
Add application/vnd.ms-excel , text/csv and text/plain
Arko
Arko2y ago
Also add text/plain
Noor
NoorOP2y ago
what if someone is trying to upload image or video how can i validate it saying video and image cannot be uploaded
awcodes
awcodes2y ago
Could also be text/csv
Arko
Arko2y ago
Don't validate the negative Saade mentioned that 😄
Noor
NoorOP2y ago
ok thanks everyone
awcodes
awcodes2y ago
My point still stands. Lol. More than one csv mime type.
Noor
NoorOP2y ago
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!
awcodes
awcodes2y ago
Run your file through a mime type checker. See what the actual mime type is in the file.
Noor
NoorOP2y ago
how can I do that? @awcodes
awcodes
awcodes2y ago
Google for an online checker.
Noor
NoorOP2y ago
ok mime type is text/plain I was not using it in acceptedFileTypes
awcodes
awcodes2y ago
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.
Noor
NoorOP2y ago
Yes absolutely right. Thank-you 🙂

Did you find this page helpful?