convertBase64ToBlobData(base64Data: string, contentType: string='image/png', sliceSize=512) {
const byteCharacters = atob(base64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, { type: contentType });
return blob;
}
Сначала необходимо преобразовать base64 в данные BLOB-объектов.
const blobData = this.convertBase64ToBlobData(base64content);
if (window.navigator && window.navigator.msSaveOrOpenBlob) { //IE
window.navigator.msSaveOrOpenBlob(blobData, filename);
} else { // chrome
const blob = new Blob([blobData], { type: contentType });
const url = window.URL.createObjectURL(blob);
// window.open(url);
const link = document.createElement('a');
link.href = url;
link.download = filename;
link.click();
}
}