mutate
function that can be called to create an asset. Multiple assets can be created
at once by passing in an array of sources.
Usage
- React
- React Native
mutate
function. The variables are passed into the useCreateAsset hook, and
createAsset return type is defined when the variables are truthy.
Mutation
Return Value
The return value is partially based on Tanstack Query, with some return types aggregated for simplicity. The valueprogress is an array of progress values which contains the upload
progress from tus, as well as the
processing progress of the asset from the provider. These values are polled
consistently until the asset succeeds or fails to be processed by the provider.
Configuration
sources
Thesources used for the asset creation can be an array of either a URL or a
local File/ReadStream/object with a uri string. It is highly recommended to
use
const assertions
to infer types properly from the sources parameter - please see below for an
example.
- React
- React Native
"
The
useCreateAsset hook uses tus for
resumable uploads and checks for existing uploads by default, before starting
a new upload. It also automatically polls the livepeer provider’s API to
update status until the import job is complete.sources type can be either a URL or a File/ReadStream:
We are planning on adding further features to the creator ID such as provable
claims. Reach out to us on Discord if you’re
interested!
CreateAssetSourceFile is passed in the array, the useCreateAsset hook
uses tus for resumable uploads and
checks for existing uploads by default, before starting a new upload.
If CreateAssetSourceUrl is passed in the array, the hook will make a request
to the background to start an import. This can also be an IPFS URL
(ipfs://<CID>) or Arweave URL (ar://<HASH>). Either a URL or file must be
provided.
storage
Thestorage configs can be applied on asset creation. See useUpdateAsset for
more details on these configs. If the storage parameter is omitted, the asset
will not be stored in decentralized storage.
If you would like to use Arweave as storage, we recommend you upload to
Arweave first and then import the video.
noWait
ThenoWait config option skips the polling mechanism which waits for the Asset
upload to succeed or fail. It will immediately return after the file upload is
complete, or in the case of a URL upload, it will return after the URL is
POSTed to the backend.
mutationConfig
ThemutationConfig parameter allows for any
Tanstack Query
useMutation options, such as cacheTime or retry. These override any
configs passed by default by the internal hook.