Depending on the attributes that you pass, you can use this endpoint to:
author
, notes
, copyright
, default_field_metadata
, etc.;basename
attribute;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.
Upload path
Upload basename
Copyright
Author
Notes
Tags
For each of the project's locales, the default metadata to apply if nothing is specified at record's level.
The entity (account/collaborator/access token) who created the asset
Upload collection to which the asset belongs
import {buildClient,uploadLocalFileAndReturnPath,} from "@datocms/cma-client-node";async function run() {// Make sure the API token has access to the CMA, and is stored securelyconst 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 filefilename: "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();