/** * Forces a download from the client side. * @param content The content of the file to be downloaded * @param {string} contentType The type of the content. ex: txt/csv, application/json, application/octet-stream * @param {string} fileName The filename, including the extension. */ export function forceDownload( content: any, contentType: string, fileName: string ) { let blobContent: Array; if (Array.isArray(content)) { blobContent = content; } else { blobContent = [content]; } const blob = new Blob(blobContent, { type: contentType }); const url = window.URL.createObjectURL(blob); // Force the download const a = document.createElement('a'); a.href = url; a.download = fileName; a.style.display = 'none'; document.body.appendChild(a); a.click(); // Clean up window.URL.revokeObjectURL(url); document.body.removeChild(a); }