AuthorBuddy/wwwroot/js/download.js
2026-05-31 19:31:27 +02:00

14 lines
561 B
JavaScript

window.downloadFile = function (fileName, base64, mimeType) {
const byteChars = atob(base64);
const bytes = new Uint8Array(byteChars.length);
for (let i = 0; i < byteChars.length; i++) bytes[i] = byteChars.charCodeAt(i);
const blob = new Blob([bytes], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => URL.revokeObjectURL(url), 10000);
};