Created
September 10, 2020 12:51
-
-
Save arefaslani/1e907830c4d4528071c2bac19f941bea to your computer and use it in GitHub Desktop.
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
const file = document.querySelector("input[type=file]").files[0]; | |
const reader = new FileReader(); | |
reader.readAsArrayBuffer(file); | |
reader.onload = () => { | |
const key = require("../arweave-keyfile.json"); | |
const arweave = Arweave.init({ | |
host: "arweave.net", | |
port: 443, | |
protocol: "https", | |
timeout: 20000, | |
logging: false, | |
}); | |
arweave | |
.createTransaction({ data: Buffer.from(reader.result) }, key) | |
.then(async (transaction) => { | |
transaction.addTag("Content-Type", file.type); | |
await arweave.transactions.sign(transaction, key); | |
const uploader = await arweave.transactions.getUploader(transaction); | |
while (!uploader.isComplete) { | |
await uploader.uploadChunk(); | |
console.log(`${uploader.pctComplete}% complete, ${uploader.uploadedChunks}/${uploader.totalChunks}`); | |
} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment