Easily restore your project to a previous version with our new Instant One-click Backup Recovery
Hygraph
Docs

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>"}
) {
id
upload {
status
expiresAt
error {
code
message
}
}
}
}

#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}) {
id
upload {
status
expiresAt
error {
code
message
}
requestPostData {
url
date
key
signature
algorithm
policy
credential
securityToken
}
}
}
}