Safari无法上传带有未知MIME类型(?)的文件(显示“ tempimage&quot”)

发布于 2025-01-24 01:13:34 字数 777 浏览 5 评论 0原文

这是一个非常奇怪的错误,发生在Safari 15.3和15.4(MacOS)中,但没有在任何其他浏览器中。

如果我有以下元素:

<input type="file" accept=".json,.cbor">

我可以选择任何.cbor文件。

但是,如果我这样做:

<input type="file" accept=".json,.jpg,.cbor">

Safari显示一个'tempimagexxxxx.jpg'名称,并且不选择实际文件。

在我们的测试中,此唯一的发生在.cbor文件中,但是我认为这可能与未知的MIME类型有关吗? 。同样,没有其他浏览器有任何问题。重新排序元素中的扩展名。

复制:只需将TXT文件重命名为.cbor,然后将上述代码粘贴到JSFiddle中即可。

Here's a very weird bug that occurs in Safari 15.3 and 15.4 (macOS) but not in any other browser.

If I have the following element:

<input type="file" accept=".json,.cbor">

I can select any .cbor file.

Working

However, if I do:

<input type="file" accept=".json,.jpg,.cbor">

Safari shows a 'tempImageXXXXX.jpg' name and does not select the actual file.

Broken

This only happens for .cbor files in our test, but I assume it might have something to do with unknown mime types? .wav, .json, .jpeg, .mp4, etc. all have no issues. Also no other browser has any issues with this. Re-ordering the extensions in the element neither.

To replicate: just rename a txt file to .cbor and paste the code above into jsfiddle.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丘比特射中我 2025-01-31 01:13:34

尝试使用以下操作:

<input type="file" accept="application/json,image/jpg,.cbor" />

如果不正常,请尝试使用.cbor使用text/plain

try using this:

<input type="file" accept="application/json,image/jpg,.cbor" />

if that did not work fine, try changing .cbor with text/plain

凉墨 2025-01-31 01:13:34

实际答案是,当Accept html元素的标签中列出了图像哑光型时,WebKit(Safari背后的Web引擎)正在转换图像。这已被引入 webkit的更改,并且在他们的中使用了以下更改。当图像从照片应用程序中拖动时,将HEIC图像即时转换为JPEG的示例。

但是,在OCUS上,我们发现与此更改链接的错误。对于某些MIME类型(我无法列出)文件的名称已更改为tempimagexxxxx。 OP的修复程序之所以使用,是因为他们使用image/*而不是Accept字段中的特定图像Mime-type。

因此,真正的修复是上述错误。
当时您可以使用:

<input type="file" accept="application/json,image/*,.cbor" />

您可以通过插入输入的事件来检查特定的图像MIME类型。

The actual answer is that Webkit (the web engine behind Safari) is converting images when an image mime-type is listed in the accept tag of an HTML element. This has been introduced with the following change in Webkit and it is used in their example to transform HEIC images into JPEG on the fly when an image is drag and dropped from the Photos app.

However, at Ocus, we discovered a bug linked to this change. For some mime-types (which I haven't been able to list) the name of the file is changed to tempImageXXXXX. The OP's fix worked because they used image/* instead of a specific image mime-type in the accept field.

So, the real fix is the above bug.
What you can do meanwhile is use:

<input type="file" accept="application/json,image/*,.cbor" />

You can check for specific image mime-type by plugging into the input's events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文