Client side csv download using Blob
suggest changefunction downloadCsv(csvString) {
const blob = new Blob([csvString], { type: "text/csv" });
if (window.navigator.msSaveOrOpenBlob) {
// Legacy Internet Explorer.
window.navigator.msSaveBlob(blob, "filename.csv");
return;
}
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "filename.csv";
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(a.href);
}
downloadCsv("a1,a2,a3");
URL.createObjectURL takes only the blob. The MIME type belongs on the Blob. This runs in a browser, and the download name is a hint the user can change.
Source: https://github.com/mholt/PapaParse/issues/175
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents