Skip to content

Instantly share code, notes, and snippets.

@mhingston
Created February 25, 2018 13:24
Show Gist options
  • Save mhingston/fb4f11b0cfdd9c9fbca9ff2afd7633bc to your computer and use it in GitHub Desktop.
Save mhingston/fb4f11b0cfdd9c9fbca9ff2afd7633bc to your computer and use it in GitHub Desktop.
IPFS-JS Stub
const main = () =>
{
const node = new Ipfs();
node.on('ready', () =>
{
document.getElementById('files').addEventListener('change', handleFileSelect, false);
});
const handleFileSelect = (event) =>
{
const files = event.target.files;
for(const file of files)
{
const reader = new FileReader();
reader.onload = (event) =>
{
node.files.add(buffer.Buffer.from(event.target.result), (error, response) =>
{
console.log(error);
console.log(response);
});
}
reader.readAsArrayBuffer(file);
}
}
}
document.addEventListener('DOMContentLoaded', main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment