Data mode

The chunked uploader has two modes of operation, data mode and transaction mode. When using data mode do not create a transaction, this will be done automatically for you.

Within data mode, you can either upload using:

  • A buffer containing the data you want to upload.
  • A readable stream pointing to the data you want to upload.

uploader.uploadData()

// The uploader has two modes of operation, data mode and transaction mode.
// When using data mode, do not create a transaction, this will be done
// automatically for you.
const transactionOptions = { tags: [{ name: "Content-Type", value: "text/plain" }] };
// Within data mode you have two options:
// 1. Using a Buffer containing just the data you want to upload.
const dataBuffer = Buffer.from("Hello, world!");
const response = await uploader.uploadData(dataBuffer, transactionOptions);
// The transaction id (used to query the network) is found in response.data.id
console.log(`Data buffer uploaded ==> https://gateway.irys.xyz/${response.data.id}`);
 
// 2. Using a Readable (stream) pointing to the data
uploader = irys.uploader.chunkedUploader; // Recreate for each transaction
const dataStream = fs.createReadStream("./data.txt");
response = await uploader.uploadData(dataStream, transactionOptions);
console.log(`Read Stream uploaded ==> https://gateway.irys.xyz/${response.data.id}`);