We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents b9864e5 + ac54eab commit ae1563dCopy full SHA for ae1563d
1 file changed
downloadFile.js
@@ -1,12 +1,15 @@
1
-const downloadFile = (name, uint8arry) => {
+import { CONTENT_TYPE } from "https://code4sabae.github.io/js/CONTENT_TYPE.js";
2
+
3
+export const downloadFile = (name, uint8arry) => {
4
+ const ext = name.split('.').pop().toLowerCase();
5
+ const mime = CONTENT_TYPE[ext] || "application/octet-stream";
6
+ const blob = new Blob([uint8arry], { type: mime });
7
+ const url = URL.createObjectURL(blob);
8
const link = document.createElement("a");
- const dataurl = URL.createObjectURL(new Blob([uint8arry])); // , { type: "text/plain" }));
- link.href = dataurl;
9
+ link.href = url;
10
link.download = name;
11
document.body.appendChild(link);
12
link.click();
13
link.remove();
14
+ URL.revokeObjectURL(url);
15
};
-
-export { downloadFile };
0 commit comments