ThirdwebStorage class
Upload and download files from decentralized storage systems.
Signature:
export declare class ThirdwebStorage<T extends UploadOptions = IpfsUploadBatchOptions>
Example
// Create a default storage class without any configuration
const storage = new ThirdwebStorage();
// Upload any file or JSON object
const uri = await storage.upload(data);
const result = await storage.download(uri);
// Or configure a custom uploader, downloader, and gateway URLs
const gatewayUrls = {
// We define a mapping of schemes to gateway URLs
"ipfs://": [
"https://gateway.ipfscdn.io/ipfs/",
"https://cloudflare-ipfs.com/ipfs/",
"https://ipfs.io/ipfs/",
],
};
const downloader = new StorageDownloader();
const uploader = new IpfsUploader();
const storage = new ThirdwebStorage({ uploader, downloader, gatewayUrls });
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(options) | Constructs a new instance of the ThirdwebStorage class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
gatewayUrls | GatewayUrls |
Methods
Method | Modifiers | Description |
---|---|---|
download(url) | Downloads arbitrary data from any URL scheme. | |
downloadJSON(url) | Downloads JSON data from any URL scheme. Resolves any URLs with schemes to retrievable gateway URLs. | |
resolveScheme(url) | Resolve any scheme on a URL to get a retrievable URL for the data | |
upload(data, options) | 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. | |
uploadBatch(data, options) | Batch 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. |