Type Parameters

  • T extends UploadOptions = IpfsUploadBatchOptions

Hierarchy

  • ThirdwebStorage

Implements

  • IThirdwebStorage

Constructors

Properties

clientId?: string
downloader: IStorageDownloader
gatewayUrls: GatewayUrls
uploader: IStorageUploader<T>

Methods

  • Downloads arbitrary data from any URL scheme.

    Parameters

    • url: string

      The URL of the data to download

    • Optional options: SingleDownloadOptions

    Returns Promise<Response>

    The response object fetched from the resolved URL

    Example

    const uri = "ipfs://example";
    const data = await storage.download(uri);
  • Downloads JSON data from any URL scheme. Resolves any URLs with schemes to retrievable gateway URLs.

    Type Parameters

    • TJSON = any

    Parameters

    • url: string

      The URL of the JSON data to download

    • Optional options: SingleDownloadOptions

    Returns Promise<TJSON>

    The JSON data fetched from the resolved URL

    Example

    const uri = "ipfs://example";
    const json = await storage.downloadJSON(uri);
  • Resolve any scheme on a URL to get a retrievable URL for the data

    Parameters

    • url: string

      The URL to resolve the scheme of

    Returns string

    The URL with its scheme resolved

    Example

    const uri = "ipfs://example";
    const url = storage.resolveScheme(uri);
    console.log(url);
  • 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.

    Parameters

    • data: any

      Arbitrary file or JSON data to upload

    • Optional options: T

      Options to pass through to the storage uploader class

    Returns Promise<string>

    • The URI of the uploaded data

    Example

    // Upload an image
    launchImageLibrary({mediaType: 'photo'}, async response => {
    if (response.assets?.[0]) {
    const {fileName, type, uri} = response.assets[0];
    if (!uri) {
    throw new Error('No uri');
    }
    const resp = await storage.upload({
    uri,
    type,
    name: fileName,
    });
    }
    });
    const jsonUri = await storage.upload(json);
  • 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.

    Parameters

    • data: any[]

      Array of arbitrary file or JSON data to upload

    • Optional options: T

      Options to pass through to the storage uploader class

    Returns Promise<string[]>

    • The URIs of the uploaded data

    Example

    // Upload an image
    launchImageLibrary({mediaType: 'photo'}, async response => {
    if (response.assets?.[0]) {
    const {fileName, type, uri} = response.assets[0];
    if (!uri) {
    throw new Error('No uri');
    }
    const resp = await storage.upload({
    uri,
    type,
    name: fileName,
    });
    }
    });

    // Upload an array of JSON objects
    const objects = [
    { name: "JSON 1", text: "Hello World" },
    { name: "JSON 2", trait: "Awesome" },
    ];
    const jsonUris = await storage.uploadBatch(objects);

Generated using TypeDoc