uploadFile(fileName, tags?)

Uploads a file to Irys.

Parameters

NameTypeDescription
fileNamestringName of the file to upload.
tagsTag[](Optional) Metatags.

Returns

Returns an object with the following value:

response = {
  id,              // Transaction ID (used to download the data)
}

The response also carries the fields of the legacy receipt object. They are kept for backwards compatibility, are not documented, and should not be relied on.

Funding

Note
Note
Uploads of less than 100 KiB are free. For larger uploads, you'll need to fund your account first.

Example

Note
Note
Use a token-specific version of getIrysUploader() to connect to an Irys Bundler before uploading. Choose one from the setup documentation.
const irys = await getIrysUploader();

// Your file
const fileToUpload = "./myImage.png";

// Add a custom tag that tells the gateway how to serve this file to a browser
const tags = [{ name: "Content-Type", value: "image/png" }];

try {
  const response = await irys.uploadFile(fileToUpload, tags);
  console.log(`File uploaded ==> https://gateway.irys.xyz/${response.id}`);
} catch (e) {
  console.log("Error uploading file ", e);
}

Downloading

Use the transaction ID returned as part of the response to download the data by creating a URL in the format https://gateway.irys.xyz/:transactionId.