Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.