How to download a blob file from Chrome iOS in Javascript?
var reader = new FileReader();
var out = new Blob([response.data], { type: 'application/pdf' });
reader.onload = function(e) {
window.location.href = reader.result;
}
reader.readAsDataURL(out);
// var blob = new Blob([response.data], { type: "application/pdf" });
var fileURL = URL.createObjectURL(out);
var a = document.createElement('a');
a.href = fileURL;
a.target = '_blank';
a.download = 'lkn_' + id + '.pdf';
document.body.appendChild(a);
a.click();
After searching, this solution seems to works fine on ChromeiOS and Safari. I found it on this post How to open Blob URL on Chrome iOS. This solved my problem:
//isbContentType i.e. 'text/plain'
//isbFilename i.e. 'This is a title'
var reader = new FileReader();
reader.onload = function(e) {
var bdata = btoa(reader.result);
var datauri = 'data:' + isbContentType + ';base64,' + bdata;
window.open(datauri);
newWindow = setTimeout(function() {
newWindow.document.title = isbFilename;
}, 10);
};
reader.readAsBinaryString(iobBLOB);
I believed there was a way to download the blob file, but it wasn't. Thanks anyway