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.
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.
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.
Please try this header:
accept="application/JSON"
It worked for me.
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