I'm trying to upload a file to IPFS and display the returning hash address on a browser using JavaScript and HTML. But I don't know how to handle the JavaScript API.
My HTML code:
<p id="text"> This is the IPFS address </p>
<input type="file" id="myFile">
<button onClick="submitFile()"> Submit </button>
My JavaScript code looks something like this (assuming to be linked from an external file):
submitFile(){
var tempFile = document.getElementById('myFile').value;
var nameHash;
ipfs.add(tempFile, function(err, hash) {
nameHash = hash;
}
document.getElementById("text").innerHTML = nameHash;
}
I know I am missing a lot of stuff. I've been trying to read the documentation on GitHub but it just gets more confusing.
Specifically, I don't know how to manage the modules. As in, which one am I supposed to import and what do I do with them once that is done?
Reference: https://www.reddit.com/r/ipfs/comments/4cf6pe/ipfs_browser_file_upload/
Reference: https://www.npmjs.com/package/ipfs-js