Skip to content

Commit ae1563d

Browse files
authored
Merge pull request #1 from nknhb966/master
ありがとうございます!
2 parents b9864e5 + ac54eab commit ae1563d

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

downloadFile.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
const downloadFile = (name, uint8arry) => {
1+
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);
28
const link = document.createElement("a");
3-
const dataurl = URL.createObjectURL(new Blob([uint8arry])); // , { type: "text/plain" }));
4-
link.href = dataurl;
9+
link.href = url;
510
link.download = name;
611
document.body.appendChild(link);
712
link.click();
813
link.remove();
14+
URL.revokeObjectURL(url);
915
};
10-
11-
export { downloadFile };
12-

0 commit comments

Comments
 (0)