Reputation: 6701
I am trying to convert a base64
string to byte array and open it as a pdf
file in IE. The only problem is atob
is not supported in IE, so trying to use Buffer like this:
let b64Data = myBase64Url.split(',', 2)[1];
var byteArray = new Buffer(b64Data ,'base64').toString('binary');
var blob = new Blob([byteArray], {type: 'application/pdf'});
window.navigator.msSaveOrOpenBlob(blob);
I am getting a popup successfully to open the file
But the file is corrupted
What am i doing wrong ? Is there a better way to convert base64
to byte array in IE ?
Upvotes: 3
Views: 9327
Reputation: 18281
In order for the base64 to be properly decoded, it must be only the base64 data, i.e. no mimetype information preceding it.
You will also need to remove .toString('binary')
so that you're passing a buffer instead of a string.
Upvotes: 1