Hi All,
I came across a situations where i need to download bigger file like doc/docx/txt file on Internet Explorer.
Chrome works fine to download more than 50MB file but IE does not download even a 3 MB word file and gives out of memory issue or Not enough storage is available to complete this operation.
My colleague has written below code to download any file on IE and we are supporting only IE.
Below is my code:-
function saveFile(fileName, data, fileType)
{
b64toBlob(data, fileType, function (blob)
{
if (window.navigator.msSaveOrOpenBlob)
{
window.navigator.msSaveBlob(blob, fileName);
}
else
{
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = fileName;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
});
}
function b64toBlob(b64Data, contentType, callback, sliceSize)
{
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize)
{
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++)
{
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, { type: contentType });
return callback(blob);
}
Here,
Parameter filetype is ->
docx = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
doc = "application/msword"
txt = "text/plain",
And parameter data is some long text which gets appended by File Reader while uploading every file.
For ex below see below file:-
Here doc1.docx is my file name and rest characters are appended by file reader object.
doc1.docx%^&0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAJwAAAAAAAAAAEAAAKQAAAAEAAAD+////AAAAACYAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAsRUAAAAAAACxFQAAAAAAAGsWAAAAAAAAsRUA///wAAAAD/////AAAAAIAbAAAAAAAAsRUAAAAAAA==".
How to allow downloading a file on Internet Explorer having bigger size.
I have no clue to resolve above issue. It's giving “out of memory" or "Not enough storage is available to complete this operation" exception on IE when downloading bigger file.
When size is in KB then IE handles.