Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created November 18, 2018 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/0c11d5c65e5e41edccfe50242a1e1159 to your computer and use it in GitHub Desktop.
Save tmcw/0c11d5c65e5e41edccfe50242a1e1159 to your computer and use it in GitHub Desktop.
<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