I am trying to upload large amount of file using File reader.
The current code is working for file till 150 MB only.
I came across this method 'readAsArrayBuffer' which can read large amount of files. But when tried using this method not able to read data as its throwing memory out space exception in browser.
private ProcessReadFile(file:File){
return new Promise<void>(resolve=>{
const reader=new FileReader();
let content:any;
reader.onloadend=()=>{
content=reader.result;'
const filecontent=content.split(base64,')[1];
this.fileupload.push({
Filecontent:filecontent,
FileName=file.Name
});
resolve();
};
reader.readAsDataURL(file);
});
}
With the above code able to upload file till 150 MB.
I tried with reader.readAsArrayBuffer but getting memory buffer size. I tried with the below approach to convert array buffer to base64 string and it worked. But its working when i first upload large file (around 600MB file) and when i tried to upload another large files(200MB) file its throwing "Out of Memory" browser error.
private ProcessReadFile(file:File){
return new Promise<void>(resolve=>{
const reader= new FileReader();
let content:any;
reader.onloadend=()=>{
content=reader.result;
var fileContent=_arrayBufferToBase64(content);
this.fileUpload.push({
Filecontent:fileContent;
FileType:file.Type
});
resolve;
};
});
}
Method used to convert array buffer to base 64 string. Please let me know if there is there is size limitation for window.btoa() or is it broswer cache issue.
function _arrayBufferToBase64( buffer ) {
var binary = '';
var bytes = new Uint8Array( buffer );
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
}
Please let me know how can I resolve this issue Is there anything Array buffer needs to get free after usage. So that's the reason the second time its uploaded its throwing error .