1: Get the File object
2: Read 2 binary data
3: Simulate HTTP requests, send data (usually troublesome here)
Sending data using the Sendasbinary method of the XMLHttpRequest object under Forefox;
4: Perfect Realization
Problems encountered
Currently only Firefox can upload files correctly. (Chrome can also take google.gears upload)
The file data read from Firefox and Chrome doesn't seem to be the same (I don't know if this is the reason for debugging the tool)
Chrome and other advanced browsers do not have the Sendasbinary method to send data only using the Send method, which may be the reason for the failure to upload correctly. (Test normal text files can be uploaded correctly)
Copy CodeThe code is as follows:
<title>HTML5 file and FileReader</title>
(Drag the picture here) use FileReader to get the file base64 encoding
FileReader Object
var filereader = new FileReader ();
Filereader.onloadend = function () {
Console.log (this.readystate); It's supposed to be 2 this time.
Console.log (This.result); Read completion callback function, data saved in result
}
filereader.readasbinarystring (file);//start reading 2 binary data asynchronous parameter to file object
Filereader.readasdataurl (file); Read Base64
Filereader.readastext (file);//Read text information
http://www.bkjia.com/PHPjc/323389.html www.bkjia.com true http://www.bkjia.com/PHPjc/323389.html techarticle 1: Get File object 2: Read 2 binary Data 3: Simulate HTTP request, send data out (usually troublesome here) send using Sendasbinary method of XMLHttpRequest object under Forefox ...