How to read client side file header from web page?

I am making an online tool for identifying certain types of files. I need to get some byte values ​​from the file header to do this.

The user selects a file on the client machine. One way or another, I need to get the key byte values ​​from the file, and then they will be found in the database on the server side to classify the file.

How can I read bytes from a client file?

I know that I could upload the file to the server, but these files are very large and I need only a few bytes, so it would be slow and wasteful to upload the whole file.

Can I somehow download part of the file? It seems difficult to cancel the loading of the html form, and after the cancellation, the file part is not available. Is it correct?

Can I read a file in javascript? I searched for this, but the answer is unclear. I read that this is possible with a java applet, but only if the subscriber is signed.

Is there another way?

+4
source share
2 answers

You can use html5, but you will need to cancel the flash memory or some other method other than javascript for older browsers.

http://www.html5rocks.com/en/tutorials/file/dndfiles/

+3
source

So. as stated above, you should use methods other than javascript. But each of these methods has a minus. FLASH - bad work with proxies. Really bad. Of course, you can use flash obly to get the base64 file code and pass it to js. In this case, it will work. The Java Applet is a friendly job, but not many JVM users or JVM versions may not have sasme (but if you use JDK1.4 or 1.5 thi, this is not a problem). ActiveX - only works in IE and Windows HTML5 File Api - not cross-browser. It will work only in the latest browsers and not in all.

Of course, it is much better to use the server side - in php, for example getmimetype and other functions.

But I can manually change the headers of my file. For example, I can add php files from jpeg or png to the headers and your script will think that this is an image.

So this is a bad solution: use headers. To check the filetype file, you can simply use the mimetype of the user trust file and generate an icon through the file extension

+1
source

All Articles