Skip to content

Instantly share code, notes, and snippets.

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 akshayaurora/f2377bafe37efc8a8d86daed7d5ca383 to your computer and use it in GitHub Desktop.
Save akshayaurora/f2377bafe37efc8a8d86daed7d5ca383 to your computer and use it in GitHub Desktop.
ether Swarm upload and download
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