Upload and download files from decentralized storage systems.
// Create a default storage class with a client ID when used in client-side applications
const storage = new ThirdwebStorage({ clientId: "your-client-id" });
// Create a default storage class with a secret key when used in server-side applications
const storage = new ThirdwebStorage({ secretKey: "your-secret-key" });
You can get a clientId and secretKey from https://thirdweb.com/create-api-key
// 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://ipfs.thirdwebcdn.com/ipfs/",
"https://cloudflare-ipfs.com/ipfs/",
"https://ipfs.io/ipfs/",
],
};
const downloader = new StorageDownloader();
const uploader = new IpfsUploader();
const clientId = "your-client-id";
const storage = new ThirdwebStorage({ clientId, uploader, downloader, gatewayUrls });