Created
April 22, 2018 03:52
-
-
Save umedaikiti/0c0eb8aae1904fd0e721c47a93e94086 to your computer and use it in GitHub Desktop.
Creating a file using javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var buf = new ArrayBuffer(8); | |
var view = new Int32Array(buf); | |
view[0] = 0x44434241; | |
view[1] = 0x48474645; | |
var file = new File(["test", "あいうえお", buf], "test.txt", {type: "text/plain"}); | |
document.getElementById("download").setAttribute("href", window.URL.createObjectURL(file)); | |
document.getElementById("download").setAttribute("download", file.name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="file.js" defer></script> | |
</head> | |
<body> | |
<a id="download">Download</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment