File input give different Mimetype for the same file in chrome or firefox. I have a wav file that I want to upload, chrome says it is audio/wav
and firefox detect audio/x-wav
.
I know those two mimetype are very similar (x-
stands for non-standard), but why are they handled differently in this case?
Here is a fiddle to illustrate this: https://jsfiddle.net/r9ae0zfd/. And here is the WAV file I used for this example: https://freesound.org/people/zagi2/sounds/391828/.
In the end the behavior that I would like is to take a .wav
file from my computer (client) and send it by HTTP to my server as audio/wav
regardless of the browser.
There's a subsequent question to this: how to harmonize this behavior?
Its important to understand that when you've stored a file on disk, the mime type is not stored within that type. Thats why we have file extensions like .jpg
or .wav
. In the internet over HTTP we don't need them. We can have an URL http://example.com/foo.wav
but send out a JPEG with the correct the JPEG mime type, and the browser will correcty render it as JPEG. It doesn't care about the file extension.
However if you are on your local file system the file extension is relevant. If you open a file called foo.wav
your operating system decides by the extension .wav
to open some audio player.
When selecting a file to upload it to the internet the bowser does a non-trivial task: It selects a mime type for the file extension. For this every browser has a mapping table, mapping known file extensions to mime types. Well, and here is the catch: this table obviously isn't identical on different browsers. So thats why you get different results in your fiddle.
Some browsers map .wav
to audio/wav
and some to audio/x-wav
.
So if your test case is downloading a file with the mime type audio.wav
and then inspecting its mime type with the fiddle you posted you don't check what mime type was sent by your server when you downloaded the file, but only what mime type is guessed for the file extension by your browser.
In both cases, if you sent out a file foo.wav
with the mime type audio/wav
or audio/x-wav
the file on your disk will be identical, and it won't be possible later to know what was the mime type your server sent for the file.
The only thing your browser can do during download is to change the file extension. For example if you sent a file http://example.com/foo
and it has audio/wav
as a mime type the browser will probably rename it to foo.wav
.
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