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