Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input's accept attribute doesn't recognise application/json?

Tags:

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

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">

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?

Edit:

Tested on:

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

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

like image 299
Juan Ferrer Avatar asked Oct 10 '17 09:10

Juan Ferrer


People also ask

How pass data from JSON to form?

Using the JSON. stringify() method then format the plain form data as JSON. Specify the HTTP request method as POST and using the header field of the Fetch API specify that you are sending a JSON body request and accepting JSON responses back. Then set the request body as JSON created from the form fields.

How do you store data from HTML form to JSON?

For this we are using json_encode() function which returns a JSON encoded string. We are making an array of values that the user fills in the HTML form. Then we pass this array into json_encode() function. Then json_encode() function returns a JSON encoded string.


1 Answers

Please try this header:

accept="application/JSON"

It worked for me.

like image 159
Sreekanth.S Avatar answered Sep 20 '22 15:09

Sreekanth.S