Show examples in:
Update an upload

Depending on the attributes that you pass, you can use this endpoint to:

  • Update regular attributes like author, notes, copyright, default_field_metadata, etc.;
  • Rename the asset by passing a different basename attribute;
  • Upload a new version of the asset by passing a different path attribute;

Just like POST /uploads endpoint, an asyncronous job ID might be returned instead of the regular response. See the Create a new upload section for more details.

We strongly recommend to use our JS or Ruby client to upload new assets, as they provide helper methods that take care of all the details for you.

Body Parameters

path  Optional  string  Example: "/45/1496845848-digital-cats.jpg"

Upload path

basename  Optional  string  Example: "digital-cats"

Upload basename

copyright  Optional  string, null  Example: "2020 DatoCMS"

Copyright

author  Optional  string, null  Example: "Mark Smith"

Author

notes  Optional  string, null  Example: "Nyan the cat"

Notes

tags  Optional  Array<string>  Example: ["cats"]

Tags

default_field_metadata  Optional  object  Example: {"en":{"title":"this is the default title","alt":"this is the default alternate text","custom_data":{"foo":"bar"},"focal_point":{"x":0.5,"y":0.5}}}

For each of the project's locales, the default metadata to apply if nothing is specified at record's level.

creator  Optional  { type: "account", id: account.id }, { type: "access_token", id: access_token.id }, { type: "user", id: user.id }, { type: "sso_user", id: sso_user.id }, { type: "organization", id: organization.id }

The entity (account/collaborator/access token) who created the asset

upload_collection  Optional  { type: "upload_collection", id: upload_collection.id }, null

Upload collection to which the asset belongs

Returns

Returns a upload resource object.

Examples

Example Update/rename assets
import {
buildClient,
uploadLocalFileAndReturnPath,
} from "@datocms/cma-client-node";
async function run() {
// Make sure the API token has access to the CMA, and is stored securely
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
const uploadId = 4124;
// we can either update regular attributes:
await client.uploads.update(uploadId, {
author: "New author!",
copyright: "New copyright",
default_field_metadata: {
en: {
alt: "new default alt",
title: "new default title",
focal_point: {
x: 0.3,
y: 0.6,
},
custom_data: {},
},
},
});
// associate a new file with the existing upload object:
await client.uploads.update(uploadId, {
path: await uploadLocalFileAndReturnPath(client, "./image.jpg", {
// if you want, you can specify a different base name for the uploaded file
filename: "different-image-name.png",
}),
});
// or rename the uploaded file in the CDN (for SEO purposes):
const updatedUpload = await client.uploads.update(uploadId, {
basename: "this-will-be-the-new-file-basename",
});
console.log(updatedUpload);
}
run();