Created
February 25, 2018 13:24
-
-
Save mhingston/fb4f11b0cfdd9c9fbca9ff2afd7633bc to your computer and use it in GitHub Desktop.
IPFS-JS Stub
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
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