Show examples in:
Javascript HTTP
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 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.

Query parameters

replace_strategy enum

Strategy to use when replacing the asset file. If not specified, a new URL will be generated.

Example: "keep_url"
create_new_url

Generate a new URL for the asset (default behavior)

keep_url

Maintain the same URL by overwriting the file at the existing path

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

Returns

Returns a resource object of type upload

Other examples

This example demonstrates how to update the metadata attributes of an existing asset without changing the underlying file.

You can update fields like:

  • author: The creator or photographer of the asset
  • copyright: Copyright information for the asset
  • default_field_metadata: Per-locale default metadata including alt text, title, focal point, and custom data

The default_field_metadata object allows you to set defaults that will be used when the asset is referenced in records, unless overridden at the record level.

import { buildClient } 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 = "FWYwxZZ1SUG1ReKlzdDAEA";
const updatedUpload = 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: {},
},
},
});
console.log({
id: updatedUpload.id,
author: updatedUpload.author,
copyright: updatedUpload.copyright,
default_field_metadata: updatedUpload.default_field_metadata,
});
}
run();
{
id: 'FWYwxZZ1SUG1ReKlzdDAEA',
author: 'New author!',
copyright: 'New copyright',
default_field_metadata: {
en: {
alt: 'new default alt',
title: 'new default title',
focal_point: [Object],
custom_data: {}
}
}
}

This example demonstrates how to replace the file associated with an existing upload while keeping the same upload ID.

When replacing an asset, you have two options:

Create new URL (default): The new asset is available immediately with a fresh URL. The old URL will be purged from cache and will disappear after complete propagation. Use this when you need immediate availability of the new file.

Keep the original URL: Existing links continue to work automatically, but changes take 5-10 minutes to appear everywhere due to CDN and browser cache propagation. Some users may temporarily see the old version. Use this when you have many existing references and want to avoid updating URLs.

Important considerations for keep_url

The keep_url option is only available when the new file has the same format/extension as the original (e.g., replacing a .jpg with another .jpg/.jpeg). If the formats differ, you must use the default create_new_url strategy.

Also note that since different upload entities across environments can share the same asset URL, using keep_url will automatically update all uploads that reference this asset path. This ensures consistency across environments but means the change affects more than just the current upload.

The uploadLocalFileAndReturnPath() helper handles:

  • Requesting upload permissions from DatoCMS
  • Uploading the file to the storage bucket
  • Returning the path to use in the update call
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 });
// Fetch the original uploads to show their URLs before replacement
const original1 = await client.uploads.find("bDb8xUJIRaGteyJYldfKsA");
const original2 = await client.uploads.find("II2mHvSkQESUl-2401HZgg");
console.log("Before replacement:");
console.log(" Upload 1 URL:", original1.url);
console.log(" Upload 2 URL:", original2.url);
// Upload the new file and get the path
const newFilePath = await uploadLocalFileAndReturnPath(
client,
"./new-image.jpg",
);
// ============================================================
// Option 1: Create new URL (default)
// ============================================================
// The new asset is available immediately with a fresh URL.
// Use this when you need immediate availability.
const uploadWithNewUrl = await client.uploads.update(
"bDb8xUJIRaGteyJYldfKsA",
{ path: newFilePath },
);
// ============================================================
// Option 2: Keep the original URL
// ============================================================
// Existing links work automatically, but changes take 5-10 minutes
// to propagate. Use this when you have many existing references.
const uploadKeepingUrl = await client.uploads.update(
"II2mHvSkQESUl-2401HZgg",
{ path: newFilePath },
{ replace_strategy: "keep_url" },
);
console.log("\nAfter replacement:");
console.log(" Option 1 (new URL):", uploadWithNewUrl.url);
console.log(" Option 2 (keep URL):", uploadKeepingUrl.url);
}
run();
Before replacement:
Upload 1 URL: https://www.datocms-assets.com/190734/1768292263-old-image.jpg
Upload 2 URL: https://www.datocms-assets.com/190734/1768292270-old-image.jpg
After replacement:
Option 1 (new URL): https://www.datocms-assets.com/190734/1768292279-new-image.jpg
Option 2 (keep URL): https://www.datocms-assets.com/190734/1768292270-old-image.jpg

This example demonstrates how to rename an uploaded file in the CDN by changing its basename.

This is particularly useful for SEO purposes, as the filename becomes part of the asset's URL. Renaming allows you to use descriptive, keyword-rich filenames without needing to re-upload the file.

The basename is the filename without the extension. For example, setting basename to "premium-headphones" for a .jpg file would result in a URL ending in premium-headphones.jpg.

import { buildClient } 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 = "ey4EL5V0QYCdODxbbUj2cQ";
// 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({
id: updatedUpload.id,
basename: updatedUpload.basename,
path: updatedUpload.path,
url: updatedUpload.url,
});
}
run();
{
id: 'ey4EL5V0QYCdODxbbUj2cQ',
basename: 'this-will-be-the-new-file-basename',
path: '/190729/1768291467-this-will-be-the-new-file-basename.jpeg',
url: 'https://www.datocms-assets.com/190729/1768291467-this-will-be-the-new-file-basename.jpeg'
}