React Hook for creating a new asset.
mutate
function that can be called to create an asset. Multiple assets can be created
at once by passing in an array of sources
.
playbackId
, which is a
limited identifier that provides only the ability to stream media using the
Player
.mutate
function. The variables are passed into the useCreateAsset
hook, and
createAsset
return type is defined when the variables are truthy.
progress
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.
sources
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.
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:
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
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.
noWait
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
POST
ed to the backend.
mutationConfig
parameter allows for any
Tanstack Query
useMutation
options, such as cacheTime
or retry
. These override any
configs passed by default by the internal hook.