egg server file transfer flows browser to download, stream when the file reaches 2M chrome tips direct download failed - Network error

 

 Before use FileReader code stream file will be read the file size limit transferred browser chrome;

 

Now changed 

URL.createObjectURL method of deriving from chrome browser file transfer limit
 
                let xhr = new XMLHttpRequest();
                    xhr.open ( "GET", url, true); // POST method may also be used, according to the interface
                    xhr.responseType = "blob"; // return type blob, XMLHttpRequest support binary stream type
                    xhr.onload = function() {
                        if (this.status === 200) {  
                            let blob = this.response; // return a response to use, instead of responseText
                            const objectURL = URL.createObjectURL (new Blob ([blob], {type: 'text / xls'})) // chrome from the file size limit export file you
                            // let reader = new FileReader();
                            // reader.readAsDataURL (blob); // convert base64, directly into a href tag
                            // objectURL.onload = function(e) {
                            // conversion is complete, create a label for a download
                            let a = document.createElement("a");
                            a.download = "xxxxxx.xlsx";
                            a.href = objectURL
                            a.click();
                            layer.msg ( 'download successful');
                            // };
                        } else {
                            layer.msg ( 'download failed');
                        }
                    };

  

 

Guess you like

Origin www.cnblogs.com/xiguachaodan/p/11907166.html