Created
April 2, 2018 14:08
-
-
Save akshayaurora/f2377bafe37efc8a8d86daed7d5ca383 to your computer and use it in GitHub Desktop.
ether Swarm upload and download
This file contains hidden or 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
previewHash(hash){ | |
var preview = document.querySelector('img'); | |
var xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
// Typical action to be performed when the document is ready: | |
preview.src = xhttp.responseText; | |
} | |
}; | |
xhttp.open("GET", "http://swarm-gateways.net/bzz:/" + hash, true); | |
xhttp.send(); | |
}, | |
uploadToSwarm() { | |
var preview = document.querySelector('img'); | |
var file = document.querySelector('input[type=file]').files[0]; | |
var reader = new FileReader(); | |
reader.addEventListener("load", function () { | |
//preview.src = reader.result; | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", "http://swarm-gateways.net/bzz:/", true); | |
xhr.setRequestHeader('Content-Type', 'text/plain'); | |
xhr.send(reader.result); | |
xhr.onload = function() { | |
hash = this.responseText; | |
console.log(hash); | |
} | |
}, false); | |
if (file) { | |
reader.readAsDataURL(file); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment