Sorry, no results found for "".

Show examples in:
Javascript HTTP

Content Management API > Upload

List all uploads

To retrieve a collection of uploads, send a GET request to the /uploads endpoint. The collection is paginated, so make sure to iterate over all the pages if you need every record in the collection!

The following table contains the list of all the possible arguments, along with their type, description and examples values.

Pro tip: in case of any doubts you can always inspect the network calls that the CMS interface is doing, as it's using the Content Management API as well!

Query parameters

filter object

Attributes to filter uploads

ids string

IDs to fetch, comma separated

Example: "12,31"
query string

Textual query to match. If locale is defined, search within that locale. Otherwise environment's main locale will be used.

Example: "foobar"
fields object

Same as GraphQL API uploads filters. Use snake_case for fields names. If locale is defined, search within that locale. Otherwise environment's main locale will be used.

Example: { type: { eq: "image" }, size: { gt: 5000000 } }
locale string

When filter[query] or field[fields] is defined, filter by this locale. Default: environment's main locale

Example: "it"
order_by string

Fields used to order results. Format: <field_name>_<DIRECTION(ASC|DESC)>. You can pass multiple comma separated rules.

Example: "_created_at_DESC,size_ASC"
page object

Parameters to control offset-based pagination

offset integer

The (zero-based) offset of the first entity returned in the collection (defaults to 0)

Example: 200
limit integer

The maximum number of entities to return (defaults to 30, maximum is 500)

Returns

Returns an array of resource objects of type upload

Other examples

The client.uploads.list() method returns a single page of records, while if you need to iterate over every resource in the collection (and not just the first page of results), you can use the client.uploads.listPagedIterator() method with an async iteration statement, which automatically handles pagination for you.

All the details on how to use list() and listPagedIterator() are outlined on this page.

import { buildClient } from "@datocms/cma-client-node";
async function run() {
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
// iterates over every page of results
for await (const upload of client.uploads.listPagedIterator()) {
// Check the 'Returned output' tab for the result ☝️
console.log(upload);
}
}
run();

You can retrieve a list of uploads filtered by a set of conditions. There are different options and you can combine multiple filters together.

In this example we are filtering by type and size. In particular, we are searching for images bigger than 5MB.

The filtering options are the same as the GraphQL API uploads filters. So please check there all the options.

import { buildClient } from "@datocms/cma-client-node";
async function run() {
// Make sure the API token has access to the CMA, and is stored securely
const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
const uploads = await client.uploads.list({
filter: {
fields: {
type: {
eq: "image",
},
size: {
gt: 5000000,
},
},
},
});
console.log(uploads);
}
run();