Build
ONCHAIN STORAGE
SDK
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 (testnet)
  • Input data
  • Configured chunk size

uploader.pause() and uploader.resume()

ℹ️

Use a token-specific version of getIrysUploader() to connect to an Irys Bundler before uploading. Choose one from here.

const irys = await getIrysUploader();
 
// 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;