Show examples in:
    Create a new upload

    The DatoCMS clients provide numerous methods for users to upload resources. The method you choose can be influenced by different aspects like the platform you're using (such as Node.js or a browser) and where the resource is coming from — like a local file, a remote URL, or a File or Blob obtained from <input type="file" /> elements.

    Example Node.js: Create an upload from a local file
    Example Node.js: Create an upload from a remote URL
    Example Browser: Create an upload from a File or Blob object
    Example Monitoring the progress

    Each available method yields a cancellable promise, granting the ability to halt a currently running upload operation.

    Example Cancelling an in-progress upload

    It is possible to cancel an upload operation by calling the .cancel() method on the promise returned by one of the upload creation methods (createFromUrl(), createFromLocalFile() in NodeJS, createFromFileOrBlob() in browser):

    import { buildClient, CanceledPromiseError } from "@datocms/cma-client-browser";
    // Make sure the API token has access to the CMA, and is stored securely
    const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
    let cancelablePromise = null;
    document.querySelector("button").addEventListener("click", () => {
    if (cancelablePromise) {
    .addEventListener("change", async (event) => {
    cancelablePromise = client.uploads.createFromFileOrBlob({
    .then((upload) => {
    cancelablePromise = null;
    .catch((e) => {
    if (e instanceof CanceledPromiseError) {
    console.log("User canceled the upload process!");
    } else {
    throw e;

    Body Parameters

    id  string  Optional
    RFC 4122 UUID of upload expressed in URL-safe base64 format
    path  Required  string  Example: "/45/1496845848-digital-cats.jpg"

    Upload path

    copyright  Optional  string, null  Example: "2020 DatoCMS"


    author  Optional  string, null  Example: "Mark Smith"


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


    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.

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



    Returns a upload resource object.