Content Management API > Upload
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
basenameattribute; - Upload a new version of the asset by passing a different
pathattribute;
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 string Optional
Upload path
Example:
"/45/1496845848-digital-cats.jpg"
basename string Optional
Upload basename
Example:
"digital-cats"
copyright string, null Optional
Copyright
Example:
"2020 DatoCMS"
author string, null Optional
Author
Example:
"Mark Smith"
notes string, null Optional
Notes
Example:
"Nyan the cat"
tags Optional
Tags
Type:
Array<string>
Example:
["cats"]
default_field_metadata object Optional
For each of the project's locales, the default metadata to apply if nothing is specified at record's level.
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 },
},
}
creator Optional
The entity (account/collaborator/access token) who created the asset
upload_collection Optional
Upload collection to which the asset belongs
Type:
ResourceLinkage<"upload_collection">, null
Returns
Returns a resource object of type upload
Other examples
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();{ id: "q0VNpiNQSkG6z0lif_O1zg", size: 444, width: 30, height: 30, path: "/45/1496845848-digital-cats.jpg", basename: "digital-cats", filename: "digital-cats.jpg", url: "https://www.datocms-assets.com/45/1496845848-digital-cats.jpg", format: "jpg", author: "Mark Smith", copyright: "2020 DatoCMS", notes: "Nyan the cat", md5: "873c296d0f2b7ee569f2d7ddaebc0d33", duration: 62, frame_rate: 30, blurhash: "LEHV6nWB2yk8pyo0adR*.7kCMdnj", thumbhash: "UhqCDQIkrHOfVG8wBa2v39z7CXeqZWFLdg==", mux_playback_id: "a1B2c3D4e5F6g7H8i9", mux_mp4_highest_res: "high", default_field_metadata: { 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 }, }, }, is_image: true, created_at: "2020-04-21T07:57:11.124Z", updated_at: "2020-04-21T07:57:11.124Z", mime_type: "image/jpeg", tags: ["cats"], smart_tags: ["robot-cats"], exif_info: { iso: 10000, model: "ILCE-7", flash_mode: 16, focal_length: 35, exposure_time: 0.0166667, }, colors: [ { red: 206, green: 203, blue: 167, alpha: 255 }, { red: 158, green: 163, blue: 93, alpha: 255 }, ], creator: { type: "account", id: "312" }, upload_collection: { type: "upload_collection", id: "uinr2zfqQLeCo_1O0-ao-Q", },}