javascript - HTML file upload: is there a way to force content-type="application/octet-stream" -


we custom handling file uploads on server end due embedded limitations.

the html file upload code used in firefox browser:

<html> <body>     <form action="http:///192.168.1.1/upload.cgi" name="form_1" method="post" enctype="multipart/form-data" >         <input type="file" id="file" name="filename" content-type="application/octet-stream">         <input type="submit" name="mysubmit" value="send">     </form> <body> </html>  

if selected file called "fish.jpg", server receives content-type "image/jpeg". if file renamed "fish" without file extension, server receives content-type "application/octet-stream" want.

is there way force "application/octet-stream" in html page (with or without regular javascript)?

thanks in advance, bert

no. there no content-type="..." attribute. cannot influence browser's choice of content-type header in multipart/form-data subpart @ all, or without javascript.

why matter? it's bad idea server-side script content-type, it's inaccurate. treating image/jpeg uploads differently application/octet-stream shouldn't done, not least because browser may choose upload jpeg application/octet-stream or else (in particular, ie likes send image/pjpeg).

if control server side , getting right file upload type critical, there should interface user select manually. (you can use javascript file extension sniffing and/or content-type set default value, don't rely on either.)


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -