Updating assets
#Overview
Since assets are a system model, and automatically added to every project, you can extend them with your own custom fields.
These fields can be updated using GraphQL mutations.
#Update metadata
In the following example, we have added altText
and caption
fields to our Assets model. Here, we are using an updateAsset
mutation to change the text in them:
After successfully running this mutation, if you access your asset in edit mode, you will see the new altText
and caption
.
Learn more about Mutations.
#Update existing asset
The Hygraph Asset Management System offers a way to update an existing asset entry and reuploading a new file for it.
To do this, there is a route to do a file upload, or a remote URL upload.
#Update via remote URL
Use reUpload: true
as follows:
mutation test {updateAsset(where: {id: "<YOUR_ASSET_ID>"}data: {reUpload: true, uploadUrl: "<NEW_ASSET_URL>"}) {idupload {statusexpiresAterror {codemessage}}}}
#Update via file upload
To update an asset via file upload you need to follow the asset upload async process, with the data you get from requestPostData
to send the local file to S3.
Use reUpload: true
as follows:
mutation test {updateAsset(where: {id: "<YOUR_ASSET_ID>"}, data: {reUpload: true}) {idupload {statusexpiresAterror {codemessage}requestPostData {urldatekeysignaturealgorithmpolicycredentialsecurityToken}}}}