Choose your language:
    Update an upload

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

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

    Just like POST /uploads endpoint, we might return an asyncronous job ID 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.

    Parameters
    path  string  Optional

    Upload path

    basename  string  Optional

    Upload basename

    copyright  string, null  Optional

    Copyright

    author  string, null  Optional

    Author

    notes  string, null  Optional

    Notes

    tags  Array<string>  Optional

    Tags

    defaultFieldMetadata  object  Optional

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

    relationships.creator  { type: "account", id: account.id }, { type: "access_token", id: access_token.id }, { type: "user", id: user.id }, { type: "sso_user", id: sso_user.id }  Required

    The entity (account/collaborator/access token) who created the asset. It must be an object with type (e.g. 'account') and id properties.

    Returns
    Returns a upload object.

    Examples

    Update/rename assets
    Example code:
    const { SiteClient } = require('datocms-client');
    const client = new SiteClient('YOUR-API-TOKEN');
    async function updateUpload() {
    // let's say we have this upload
    const upload = await client.uploads.find('4124')
    // we can either update its regular attributes:
    await client.uploads.update(
    upload.id,
    {
    author: 'New author!',
    copyright: 'New copyright',
    defaultFieldMetadata: {
    en: {
    alt: 'new default alt',
    title: 'new default title',
    focalPoint: {
    x: 0.3,
    y: 0.6,
    },
    customData: {},
    },
    },
    }
    );
    // or replace its file
    await client.uploads.update(
    upload.id,
    {
    path: (await client.createUploadPath('./image.jpg')),
    }
    )
    // or rename the file (for SEO purposes)
    const updatedUpload = await client.uploads.update(
    upload.id,
    {
    basename: 'this-will-be-the-new-file-basename',
    }
    )
    console.log(updatedUpload)
    }
    updateUpload();
    Returned output:
    {
    id: "4124",
    size: 444,
    width: 30,
    height: 30,
    path: "/45/1496845848-this-will-be-the-new-file-basename.jpg",
    basename: "digital-cats",
    url: "https://www.datocms-assets.com/45/1496845848-this-will-be-the-new-file-basename.jpg",
    format: "jpg",
    author: "New author!",
    copyright: "New copyright",
    notes: "Nyan the cat",
    defaultFieldMetadata: {
    en: {
    alt: "new default alt",
    title: "new default title",
    focalPoint: {
    x: 0.3,
    y: 0.6,
    },
    customData: {}
    }
    },
    isImage: true,
    tags: [ "cats" ]
    }