Considerations for html5 filereader Reading streams: html5filereader

Source: Internet
Author: User

Considerations for html5 filereader Reading streams: html5filereader

New FileReader is required to intercept the read files, and the same reader cannot be called globally.


Error code !!!
Function readAsBinaryString (file, callback) {readrSpt (); var part = 0, fileName = file. name, step = 1024*10, start = 0, a = 0, B = 0, total = file. size, loaded = 0, reader = new FileRead (), fileType = file. type; // This write is incorrect, and the reader stream is not synchronized. // $ ("# fileLink "). attr ("href", URL. createObjectURL (blob); // read the file in the form of arraybuffer (function (start) {var blob = file. slice (start, start + step + 1), self = arguments. callee; // console. log (blob) reader. readAsArrayBuffer (blob); reader. onprogress = function (e) {loaded + = e. loaded; var per = loaded/total; if (loaded = total) {per = 100; callback (this. result, part, fileName, fileType, true);} else {per * = 100; callback (this. result, part); part ++;} reader. onload = function (e) {console. log (loaded) if (loaded <total) {self (loaded); // callback (this. result) ;}else {loaded = total ;}} (start );}


Certificate ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Correct code
Function readAsBinaryString (file, callback) {readrSpt (); var part = 0, fileName = file. name, step = 1024*10, start = 0, a = 0, B = 0, total = file. size, loaded = 0, fileType = file. type; // $ ("# fileLink "). attr ("href", URL. createObjectURL (blob); // read the file in the form of arraybuffer (function (start) {var blob = file. slice (start, start + step + 1), reader = new FileReader (), self = arguments. callee; // console. log (blob) reader. readAsArrayBuffer (blob); reader. onprogress = function (e) {loaded + = e. loaded; var per = loaded/total; if (loaded = total) {per = 100; callback (this. result, part, fileName, fileType, true);} else {per * = 100; callback (this. result, part); part ++;} reader. onload = function (e) {console. log (loaded) if (loaded <total) {self (loaded); // callback (this. result) ;}else {loaded = total ;}} (start );}
 

 

 

 


How does html5 FileaReader read files in segments?

How does a browser crash? Or page timeout?

Is the backend PHP? If yes, check whether the php. ini configuration allows uploading large files.
Upload_max_filesize maximum file size that can be uploaded. Unit: MB
Content occupied by memory_limit PHP script execution, in MB
Max_execution_time maximum PHP script execution time, in seconds
Post_max_size the maximum size of POST data. Unit: MB
Max_input_time maximum timeout time for reading uploaded data. Unit: seconds
 
In HTML5, garbled characters appear when reading a txt file containing Chinese characters using readAsText () under FileReader

Encoding problem, what is your Txt file encoding format, you can save it as a memory Gu UFT-8 try

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.