Choose your language:
    Create a new upload

    To upload a new asset to a DatoCMS project you will need to perform three separate HTTP calls. This helps DatoCMS making the uploading process extremely fast, as we don't need to be a middleman between you (the user that wants to upload an asset) and the storage bucket.

    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  Required

    Upload path

    copyright  string, null  Optional

    Copyright

    author  string, null  Optional

    Author

    notes  string, null  Optional

    Notes

    defaultFieldMetadata  object  Optional

    Metadata to apply to fields

    tags  array[string]  Optional

    Tags

    Returns
    Returns a upload object.

    Examples

    Create an upload

    This example shows how to upload local and remote files.

    Example code:
    const { SiteClient } = require("datocms-client");
    const client = new SiteClient("YOUR-API-TOKEN");
    async function createUpload() {
    // upload file using URL:
    const path = await client.createUploadPath(
    "http://i.giphy.com/NXOF5rlaSXdAc.gif"
    );
    // ...or using local files:
    const path = await client.createUploadPath("./image.png");
    // you can then use the returned path to create a new upload:
    const upload = await client.uploads.create({
    path,
    author: "New author!",
    copyright: "New copyright",
    defaultFieldMetadata: {
    en: {
    alt: "New default alt",
    title: "New default title",
    customData: {
    watermark: true,
    },
    },
    },
    });
    console.log(upload);
    }
    createUpload();
    Returned output:
    {
    id: "4124",
    size: 444,
    width: 30,
    height: 30,
    path: "/45/1496845848-image.png",
    basename: "image",
    url: "https://www.datocms-assets.com/45/1496845848-image.png",
    format: "jpg",
    author: "New author!",
    copyright: "New copyright",
    notes: null,
    defaultFieldMetadata: {
    en: {
    alt: "new default alt",
    title: "new default title",
    customData: {
    watermark: true
    }
    }
    },
    isImage: true,
    tags: []
    }
    Create an upload - one liner

    Upload a file and create an upload object in one go.

    Example code:
    const { SiteClient } = require("datocms-client");
    const client = new SiteClient("YOUR-API-TOKEN");
    async function createUpload() {
    // upload file using URL:
    const path = await client.createUploadPath(
    "http://i.giphy.com/NXOF5rlaSXdAc.gif"
    );
    // ...or using local files:
    const path = await client.createUploadPath("./image.png");
    // you can then use the returned path to create a new upload:
    const upload = await client.uploads.create({
    path,
    author: "New author!",
    copyright: "New copyright",
    defaultFieldMetadata: {
    en: {
    alt: "New default alt",
    title: "New default title",
    customData: {
    watermark: true,
    },
    },
    },
    });
    console.log(upload);
    }
    createUpload();
    Returned output:
    {
    id: "4124",
    size: 444,
    width: 30,
    height: 30,
    path: "/45/1496845848-image.png",
    basename: "image",
    url: "https://www.datocms-assets.com/45/1496845848-image.png",
    format: "jpg",
    author: "New author!",
    copyright: "New copyright",
    notes: null,
    defaultFieldMetadata: {
    en: {
    alt: "new default alt",
    title: "new default title",
    customData: {
    watermark: true
    }
    }
    },
    isImage: true,
    tags: []
    }