I'm currently struggling with Windows Browser to check mimetype of a csv
file. I've tried checking it via:
console.log($('#file')[0].files[0].type); // output: ""
But when I use Linux browser, it works fine:
console.log($('#file')[0].files[0].type); // output: "text/csv"
How could this happen? Is there any alternative solution for this? Any help would be appreciated.
Here's my Windows + browser spec:
When I tried to upload a jpg
/ png
/ any image file, Chromium can detect it's mime-type.
I'm sorry, English is not my native.
The mime-type is set by the browser depending on what it extensions it "knows" about. Internet Explorer doesn't have the mime-type for .csv see this list here. I would just check for .csv file extension manually on IE. Or you could use an external library that knows more than IE does.
Ultimately what gets placed in file.type is set by the browser. You will need to check the extension manually with either a library (I couldn't find one), or a switch statement such as this suggestion.
You can look up a list of mime-types and just add the ones you think you will encounter.
EDIT
The browser also supplies the FileReader object. You can use that to check things client-side. With Javascript being single threaded, I have no idea how well it would handle large files though. Here is a link.
The main problem is - if you have Microsoft office, then your browsers will work just fine and will see csv type, if you don't have it - it won't
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With