输入的accept属性无法识别application/json? [英] Input's accept attribute doesn't recognise application/json?

查看:786
本文介绍了输入的accept属性无法识别application/json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要用户输入文件的应用程序.它接受的文件类型之一是JSON.

I have an application that takes a file input from the user. One of the file types that it accepts is JSON.

inputaccept中的文件扩展名在大多数浏览器中都可以识别(Safari是主要的异常值),因此有时需要使用MIME类型.对于JSON,扩展名可以正常工作,但是如果您使用正确的MIME类型,则输入默认为所有文件"作为过滤器.

File extensions in input's accept are recognised fine in most browsers (Safari being the main outlier), so sometimes the use of the MIME type is required. For JSON, the extension works fine, but if you use the correct MIME type, the input defaults to "All Files" as the filter.

Extension (.json): <br>
<input type="file" accept=".json">

<br><br>

MIME type: (application/json): <br>
<input type="file" accept="application/json">

这只发生在JSON,据我所知.这是为什么?类型尚未被完全接受吗?是虫子吗?

This only happens with JSON, for what I've been able to see. Why is that? Is the type not fully accepted yet? Is it a bug?

修改:

经过测试:

                        | First | Second |
------------------------|-------|--------|
Windows 10/Chrome 61    |Success|  Fail  |
Windows 10/Firefox 56   |Success|Success |
OSX ElCapitan/Safari 9  | Fail  |Success |
Windows 10/Edge 40      |Success|  Fail  |

看到它在Firefox上运行后,我开始认为这是Chrome上的错误.

After seeing it work on Firefox, I'm starting to think it's a bug on Chrome.

推荐答案

请尝试使用此标头:

accept="application/JSON"

对我有用.

这篇关于输入的accept属性无法识别application/json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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