Controlling the upload

Controlling the upload

Uploads created with the chunked uploader can be paused and resumed at any time using the functions uploader.pause() and uploader.resume(). For these functions to work, the initial call to uploader.uploadData() or uploader.uploadTransaction() must not be preceded with the await keyword.

To resume an upload from a new uploader instance, you must use the same:

  • Token
  • Network (mainnet or devnet)
  • Input data
  • Configured chunk size

uploader.pause() and uploader.resume()

const irys = await getIrys();
// When uploading smaller files, it's common to use the await keyword before
// uploadData() or uploadTransaction(). This causes execution to pause until the file
// is fully uploaded. If you omit await, the upload happens in the background
// and you can use pause and resume as needed.
transaction = irys.createTransaction("Hello, world!");
uploader = irys.uploader.chunkedUploader; // Recreate for each transaction
const upload = uploader.uploadTransaction(transaction);
uploader.pause(); // Pauses the upload
console.log("Upload paused");
uploader.resume(); // Resumes the upload
console.log("Upload resumed");

While the initial call to uploader.uploadData() or uploader.uploadTransaction() should not use the await keyword, you can use it down the line to ensure the upload is complete.

You can call await at ANY TIME to ensure the upload has is complete.

response = await upload;