Show examples in:
Javascript HTTP

Content Management API > Upload

Update an upload

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

  • Update regular attributes like author, notes, copyright, default_field_metadata, etc.;
  • Rename the asset by passing a different basename attribute;
  • Upload a new version of the asset by passing a different 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.

Body parameters

type string Required

Must be exactly "upload".

attributes.path string Optional

Upload path

Example: "/45/1496845848-digital-cats.jpg"
attributes.basename string Optional

Upload basename

Example: "digital-cats"
attributes.copyright string, null Optional

Copyright

Example: "2020 DatoCMS"
attributes.author string, null Optional

Author

Example: "Mark Smith"
attributes.notes string, null Optional

Notes

Example: "Nyan the cat"
attributes.tags Optional

Tags

Type: Array<string>
Example: ["cats"]
attributes.default_field_metadata object Optional

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 }, }, }
relationships.creator.data Optional

The entity (account/collaborator/access token) who created the asset

relationships.upload_collection.data Optional

Upload collection to which the asset belongs

Returns

Returns a Job ID. You can then poll for the completion of the job that will eventually return a resource object of type upload

Other examples

1
PUT https://site-api.datocms.com/uploads/4124 HTTP/1.1
2
Authorization: Bearer YOUR-API-TOKEN
3
Accept: application/json
4
X-Api-Version: 3
5
Content-Type: application/vnd.api+json
6
7
{
8
"data": {
9
"id": "4124",
10
"type": "upload",
11
"attributes": {
12
"author": "Mark",
13
"copyright": "2020 DatoCMS",
14
"default_field_metadata": {
15
"en": {
16
"alt": "Nyan the cat",
17
"title": "My cat",
18
"custom_data": {}
19
}
20
}
21
}
22
}
23
}
Terminal window
1
curl -g 'https://site-api.datocms.com/uploads/4124' \
2
-X PUT \
3
-H "Authorization: Bearer YOUR-API-TOKEN" \
4
-H "Accept: application/json" \
5
-H "X-Api-Version: 3" \
6
-H "Content-Type: application/vnd.api+json" \
7
--data-binary '{"data":{"id":"4124","type":"upload","attributes":{"author":"Mark","copyright":"2020 DatoCMS","default_field_metadata":{"en":{"alt":"Nyan the cat","title":"My cat","custom_data":{}}}}}}'
1
await fetch("https://site-api.datocms.com/uploads/4124", {
2
method: "PUT",
3
headers: {
4
Authorization: "Bearer YOUR-API-TOKEN",
5
Accept: "application/json",
6
"X-Api-Version": "3",
7
"Content-Type": "application/vnd.api+json",
8
},
9
body: JSON.stringify({
10
data: {
11
id: "4124",
12
type: "upload",
13
attributes: {
14
author: "Mark",
15
copyright: "2020 DatoCMS",
16
default_field_metadata: {
17
en: { alt: "Nyan the cat", title: "My cat", custom_data: {} },
18
},
19
},
20
},
21
}),
22
});
1
HTTP/1.1 202 Accepted
2
Content-Type: application/json
3
Cache-Control: cache-control: max-age=0, private, must-revalidate
4
X-RateLimit-Limit: 30
5
X-RateLimit-Remaining: 28
6
7
{
8
"data": {
9
"type": "upload",
10
"id": "666",
11
"attributes": {
12
"size": 444,
13
"width": 30,
14
"height": 30,
15
"path": "/205/1565776891-image.png",
16
"url": "https://www.datocms-assets.com/205/1565776891-image.png",
17
"basename": "image",
18
"format": "jpg",
19
"alt": "Nyan the cat",
20
"title": "My cat",
21
"is_image": true,
22
"author": "Mark",
23
"copyright": "2020 DatoCMS",
24
"default_field_metadata": {
25
"en": {
26
"alt": "Nyan the cat",
27
"title": "My cat",
28
"custom_data": {}
29
}
30
}
31
}
32
}
33
}
1
PUT https://site-api.datocms.com/uploads/4124 HTTP/1.1
2
Authorization: Bearer YOUR-API-TOKEN
3
Accept: application/json
4
X-Api-Version: 3
5
Content-Type: application/vnd.api+json
6
7
{
8
"data": {
9
"id": "4124",
10
"type": "upload",
11
"attributes": {
12
"basename": "this-is-the-new-file-name"
13
}
14
}
15
}
Terminal window
1
curl -g 'https://site-api.datocms.com/uploads/4124' \
2
-X PUT \
3
-H "Authorization: Bearer YOUR-API-TOKEN" \
4
-H "Accept: application/json" \
5
-H "X-Api-Version: 3" \
6
-H "Content-Type: application/vnd.api+json" \
7
--data-binary '{"data":{"id":"4124","type":"upload","attributes":{"basename":"this-is-the-new-file-name"}}}'
1
await fetch("https://site-api.datocms.com/uploads/4124", {
2
method: "PUT",
3
headers: {
4
Authorization: "Bearer YOUR-API-TOKEN",
5
Accept: "application/json",
6
"X-Api-Version": "3",
7
"Content-Type": "application/vnd.api+json",
8
},
9
body: JSON.stringify({
10
data: {
11
id: "4124",
12
type: "upload",
13
attributes: { basename: "this-is-the-new-file-name" },
14
},
15
}),
16
});
1
HTTP/1.1 202 Accepted
2
Content-Type: application/json
3
Cache-Control: cache-control: max-age=0, private, must-revalidate
4
X-RateLimit-Limit: 30
5
X-RateLimit-Remaining: 28
6
7
{
8
"data": {
9
"type": "job",
10
"id": "facf9248be977002c9bae231"
11
}
12
}
1
GET https://site-api.datocms.com/job-results/facf9248be977002c9bae231 HTTP/1.1
2
Authorization: Bearer YOUR-API-TOKEN
3
Accept: application/json
4
X-Api-Version: 3
5
Content-Type: application/vnd.api+json
Terminal window
1
curl -g 'https://site-api.datocms.com/job-results/facf9248be977002c9bae231' \
2
\
3
-H "Authorization: Bearer YOUR-API-TOKEN" \
4
-H "Accept: application/json" \
5
-H "X-Api-Version: 3" \
6
-H "Content-Type: application/vnd.api+json"
1
await fetch(
2
"https://site-api.datocms.com/job-results/facf9248be977002c9bae231",
3
{
4
headers: {
5
Authorization: "Bearer YOUR-API-TOKEN",
6
Accept: "application/json",
7
"X-Api-Version": "3",
8
"Content-Type": "application/vnd.api+json",
9
},
10
},
11
);
1
HTTP/1.1 202 Accepted
2
Content-Type: application/json
3
Cache-Control: cache-control: max-age=0, private, must-revalidate
4
X-RateLimit-Limit: 30
5
X-RateLimit-Remaining: 28
6
7
{
8
"data": {
9
"type": "job-result",
10
"id": "facf9248be977002c9bae231",
11
"attributes": {
12
"status": 200,
13
"payload": {
14
"data": {
15
"type": "upload",
16
"id": "666",
17
"attributes": {
18
"size": 444,
19
"width": 30,
20
"height": 30,
21
"path": "/205/1565776891-image.png",
22
"url": "https://www.datocms-assets.com/205/1565776891-image.png",
23
"basename": "image",
24
"format": "jpg",
25
"alt": "Nyan the cat",
26
"title": "My cat",
27
"is_image": true,
28
"author": "Mark",
29
"copyright": "2020 DatoCMS",
30
"default_field_metadata": {
31
"en": {
32
"alt": "Nyan the cat",
33
"title": "My cat",
34
"custom_data": {}
35
}
36
}
37
}
38
}
39
}
40
}
41
}
42
}