⚠️ We highly advocate for utilizing our JavaScript client when uploading new assets, as it comes equipped with high-level helper methods that handle all the nitty-gritty for you.
Uploading a new asset to a DatoCMS project manually is a process that necessitates several HTTP calls. This approach significantly accelerates the upload process for DatoCMS, as it eliminates the need for us to act as an intermediary between you, the user aiming to upload an asset, and the storage bucket.
First, send a POST request to the /upload-requests endpoint to obtain the location on which to perform the physical file upload:
Now it is possible to use the obtained information to build an HTTP request that effectively uploads the file:
The HTTP method MUST be PUT
The URL is the one specified in the url attribute of the previous response
Each header specified in the request_headers attribute of the previous response MUST be set as a request header
It is possible to add a Content-Type header to specify the type of file being uploaded
The content of the file must be inserted as the raw body of the request (no multipart upload)
Make a POST request to the /uploads endpoint with the path being the ID of the request made on step 1.
You can now check if the job is complete. While the job is still processing, the endpoint returns a 404 status code. Once the job is finished, it will return a 200 status code, with the upload object in the payload.
Body parameters
idstringOptional
RFC 4122 UUID of upload expressed in URL-safe base64 format
Example: "q0VNpiNQSkG6z0lif_O1zg"
typestringRequired
Must be exactly "upload".
attributes.pathstringRequired
Upload path
Example: "/45/1496845848-digital-cats.jpg"
attributes.copyrightstring, nullOptional
Copyright
Example: "2020 DatoCMS"
attributes.authorstring, nullOptional
Author
Example: "Mark Smith"
attributes.notesstring, nullOptional
Notes
Example: "Nyan the cat"
attributes.default_field_metadataobjectOptional
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 },
},
}