Created
November 18, 2018 02:20
-
-
Save tmcw/0c11d5c65e5e41edccfe50242a1e1159 to your computer and use it in GitHub Desktop.
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
<html> | |
<script src='https://unpkg.com/ipfs@0.33.1/dist/index.min.js'></script> | |
<body> | |
<input type=text id=hash placeholder=hash/> | |
<button type=button disabled id=get>Get</button> | |
<script> | |
const ipfs = new Ipfs(); | |
ipfs.once('ready', () => { | |
const g = document.querySelector('#get'); | |
g.disabled = false; | |
g.onclick = () => { | |
ipfs.files.cat( | |
document.querySelector('#hash').value).then(file => { | |
const a = document.createElement("a"); | |
blob = new Blob([file], {type: "octet/stream"}), | |
url = window.URL.createObjectURL(blob); | |
a.href = url; | |
a.download = 'file'; | |
a.click(); | |
window.URL.revokeObjectURL(url); | |
}); | |
}; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment