Skip to main content

ThirdwebStorage.upload() method

Upload arbitrary file or JSON data using the configured decentralized storage system. Automatically uploads any file data within JSON objects and replaces them with hashes.

Signature:

upload(data: unknown, options?: T): Promise<string>;

Parameters

ParameterTypeDescription
dataunknownArbitrary file or JSON data to upload
optionsT(Optional) Options to pass through to the storage uploader class

Returns:

Promise<string>

  • The URI of the uploaded data

Example

// Upload file data
const file = readFileSync("../file.jpg");
const fileUri = await storage.upload(file);

// Or upload a JSON object
const json = { name: "JSON", image: file };
const jsonUri = await storage.upload(json);