为什么WAV格式在不同的浏览器中没有相同的模仿类型? [英] Why WAV format doesn't have same mimetype in different browsers?

查看:70
本文介绍了为什么WAV格式在不同的浏览器中没有相同的模仿类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件输入为chrome或Firefox中的同一文件提供了不同的Mimetype.我有一个要上传的wav文件,chrome表示它为 audio/wav ,而Firefox则检测为 audio/x-wav .

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.

我知道这两个模仿类型非常相似( x-代表

I know those two mimetype are very similar (x- stands for non-standard), but why are they handled differently in this case?

这里有一个小提琴来说明这一点: https://jsfiddle.net/r9ae0zfd/.这是我用于此示例的WAV文件: https://freesound.org/people/zagi2/sounds/391828/.

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/.

最后,我想要的行为是从计算机(客户端)获取一个 .wav 文件,并通过HTTP将其作为 audio/wav 无论使用哪种浏览器.

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?

推荐答案

重要的是要了解,当您将文件存储在磁盘上时,MIME类型不是存储在该类型中.这就是为什么我们要使用文件扩展名,例如 .jpg .wav .在通过HTTP的Internet中,我们不需要它们.我们可以有一个URL http://example.com/foo.wav ,但发送的JPEG具有正确的JPEG mime类型,浏览器会将其正确呈现为JPEG.它不在乎文件扩展名.

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.

但是,如果您在本地文件系统上,则文件扩展名是相关的.如果您打开一个名为 foo.wav 的文件,则操作系统将通过扩展名 .wav 来决定打开某些音频播放器.

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.

选择文件上传到Internet时,bowser会执行一项重要任务:选择文件扩展名的mime类型.为此,每个浏览器都有一个映射表,用于将已知文件扩展名映射到mime类型.好吧,这是要抓住的地方:在不同的浏览器上,此表显然并不相同.因此,这就是为什么您在小提琴中获得不同结果的原因.

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.

某些浏览器将 .wav 映射到 audio/wav ,有些将其映射到 audio/x-wav .

Some browsers map .wav to audio/wav and some to audio/x-wav.

因此,如果您的测试用例正在下载MIME类型为 audio.wav 的MIME类型的文件,然后使用您发布的小提琴检查其MIME类型,则无需检查服务器发送的是哪种MIME类型当您下载文件时,浏览器只会猜测文件扩展名是哪种MIME类型.

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.

在两种情况下,如果您发送的文件 foo.wav 的MIME类型为 audio/wav audio/x-wav 磁盘上的文件将是相同的,以后将无法知道服务器为该文件发送的哑剧类型是什么.

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.

浏览器在下载过程中唯一可以做的就是更改文件扩展名.例如,如果您发送了文件 http://example.com/foo ,并且文件中包含 audio/wav 作为哑剧类型,则浏览器可能会将其重命名为foo.wav .

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.

这篇关于为什么WAV格式在不同的浏览器中没有相同的模仿类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆