useStorageUpload

Hook used to upload any files or JSON data to decentralized storage systems like IPFS, using the storageInterface configured on the ThirdwebProvider

function useStorageUpload<T extends UploadOptions>(
  uploadOptions?: T,
): UseMutationResult<
  string[],
  unknown,
  StorageUploadOptions<T>,
  unknown
>;

Parameters


Returns

Function used to upload files or JSON to decentralized storage systems

type ReturnType = UseMutationResult<
  string[],
  unknown,
  StorageUploadOptions<T>,
  unknown
>;

Example

import { useStorageUpload } from "@thirdweb-dev/react";

export default function Component() {
  const { mutateAsync: upload, isLoading } = useStorageUpload();

  async function uploadData() {
    const filesToUpload = [...];
    const uris = await upload({ data: files });
    console.log(uris);
  }

  return (
    <button onClick={uploadData}>
      Upload
    </button>
  )
}