Files

Every file managed by the platform is uploaded to the configured storage adapter, and its associated metadata is tracked within the `directus_files` system collection. Any requested file transformations are handled on the fly, and are only saved to storage.

List Files

List all files that exist in Directus.

Query Parameters

fields
array

Control what fields are being returned in the object.

limit
integer

A limit on the number of objects that are returned.

offset
integer

How many items to skip when fetching data.

sort
array

How to sort the returned items. sort is a CSV of fields used to sort the fetched items. Sorting defaults to ascending (ASC) order but a minus sign (-) can be used to reverse this to descending (DESC) order. Fields are prioritized by their order in the CSV. You can also use a ? to sort randomly.

filter

Select items in collection by given conditions.

search
string

Filter by items that contain the given search query in one of their fields.

meta
string

What metadata to return in the response.

Response

Successful request

data
array
meta
object
GET /files
Response Example
{
  "data": [
    {
      "id": "8cbb43fe-4cdf-4991-8352-c461779cec02",
      "storage": "local",
      "filename_disk": "a88c3b72-ac58-5436-a4ec-b2858531333a.jpg",
      "filename_download": "avatar.jpg",
      "title": "User Avatar",
      "type": "image/jpeg",
      "folder": null,
      "uploaded_by": "63716273-0f29-4648-8a2a-2af2948f6f78",
      "created_on": "2019-12-03T00:10:15+00:00",
      "charset": "binary",
      "filesize": 137862,
      "width": 800,
      "height": 838,
      "duration": 0,
      "embed": null,
      "tags": [],
      "metadata": {},
      "uploaded_on": "2019-12-03T00:10:15+00:00"
    }
  ],
  "meta": {}
}

Upload a File

Upload a new file.

Request Body

[object]
object

Response

Successful request

data
object
POST /files
Response Example
{
  "data": {
    "id": "8cbb43fe-4cdf-4991-8352-c461779cec02",
    "storage": "local",
    "filename_disk": "a88c3b72-ac58-5436-a4ec-b2858531333a.jpg",
    "filename_download": "avatar.jpg",
    "title": "User Avatar",
    "type": "image/jpeg",
    "folder": null,
    "uploaded_by": "63716273-0f29-4648-8a2a-2af2948f6f78",
    "created_on": "2019-12-03T00:10:15+00:00",
    "charset": "binary",
    "filesize": 137862,
    "width": 800,
    "height": 838,
    "duration": 0,
    "embed": null,
    "tags": [],
    "metadata": {},
    "uploaded_on": "2019-12-03T00:10:15+00:00"
  }
}

Delete Multiple Files

Delete multiple existing files at once. This will also delete the files from disk.

Request Body

An array of file primary keys.

[array]
array
DELETE /files

Update Multiple Files

Update multiple files at the same time.

Query Parameters

fields
array

Control what fields are being returned in the object.

limit
integer

A limit on the number of objects that are returned.

meta
string

What metadata to return in the response.

offset
integer

How many items to skip when fetching data.

sort
array

How to sort the returned items. sort is a CSV of fields used to sort the fetched items. Sorting defaults to ascending (ASC) order but a minus sign (-) can be used to reverse this to descending (DESC) order. Fields are prioritized by their order in the CSV. You can also use a ? to sort randomly.

filter

Select items in collection by given conditions.

search
string

Filter by items that contain the given search query in one of their fields.

Request Body

data
object
keys
array

Response

Successful request

data
array
meta
object
PATCH /files
Response Example
{
  "data": [
    {
      "id": "8cbb43fe-4cdf-4991-8352-c461779cec02",
      "storage": "local",
      "filename_disk": "a88c3b72-ac58-5436-a4ec-b2858531333a.jpg",
      "filename_download": "avatar.jpg",
      "title": "User Avatar",
      "type": "image/jpeg",
      "folder": null,
      "uploaded_by": "63716273-0f29-4648-8a2a-2af2948f6f78",
      "created_on": "2019-12-03T00:10:15+00:00",
      "charset": "binary",
      "filesize": 137862,
      "width": 800,
      "height": 838,
      "duration": 0,
      "embed": null,
      "tags": [],
      "metadata": {},
      "uploaded_on": "2019-12-03T00:10:15+00:00"
    }
  ],
  "meta": {}
}

Import a File

Import a file from the web

Request Body

url
string

The URL to download the file from.

data
object

Response

Successful request

data
object
POST /files/import
Response Example
{
  "data": {
    "id": "8cbb43fe-4cdf-4991-8352-c461779cec02",
    "storage": "local",
    "filename_disk": "a88c3b72-ac58-5436-a4ec-b2858531333a.jpg",
    "filename_download": "avatar.jpg",
    "title": "User Avatar",
    "type": "image/jpeg",
    "folder": null,
    "uploaded_by": "63716273-0f29-4648-8a2a-2af2948f6f78",
    "created_on": "2019-12-03T00:10:15+00:00",
    "charset": "binary",
    "filesize": 137862,
    "width": 800,
    "height": 838,
    "duration": 0,
    "embed": null,
    "tags": [],
    "metadata": {},
    "uploaded_on": "2019-12-03T00:10:15+00:00"
  }
}

Retrieve a File

Retrieve a single file by primary key.

Query Parameters

id
string

Unique identifier for the object.

fields
array

Control what fields are being returned in the object.

meta
string

What metadata to return in the response.

Response

Successful request

data
object
GET /files/{id}
Response Example
{
  "data": {
    "id": "8cbb43fe-4cdf-4991-8352-c461779cec02",
    "storage": "local",
    "filename_disk": "a88c3b72-ac58-5436-a4ec-b2858531333a.jpg",
    "filename_download": "avatar.jpg",
    "title": "User Avatar",
    "type": "image/jpeg",
    "folder": null,
    "uploaded_by": "63716273-0f29-4648-8a2a-2af2948f6f78",
    "created_on": "2019-12-03T00:10:15+00:00",
    "charset": "binary",
    "filesize": 137862,
    "width": 800,
    "height": 838,
    "duration": 0,
    "embed": null,
    "tags": [],
    "metadata": {},
    "uploaded_on": "2019-12-03T00:10:15+00:00"
  }
}

Delete a File

Delete an existing file. This will also delete the file from disk.

Query Parameters

id
string

Unique identifier for the object.

DELETE /files/{id}

Update a File

Update an existing file, and/or replace it's file contents.

Query Parameters

id
string

Unique identifier for the object.

fields
array

Control what fields are being returned in the object.

meta
string

What metadata to return in the response.

Request Body

[object]
object

Response

Successful request

data
object
PATCH /files/{id}
Response Example
{
  "data": {
    "id": "8cbb43fe-4cdf-4991-8352-c461779cec02",
    "storage": "local",
    "filename_disk": "a88c3b72-ac58-5436-a4ec-b2858531333a.jpg",
    "filename_download": "avatar.jpg",
    "title": "User Avatar",
    "type": "image/jpeg",
    "folder": null,
    "uploaded_by": "63716273-0f29-4648-8a2a-2af2948f6f78",
    "created_on": "2019-12-03T00:10:15+00:00",
    "charset": "binary",
    "filesize": 137862,
    "width": 800,
    "height": 838,
    "duration": 0,
    "embed": null,
    "tags": [],
    "metadata": {},
    "uploaded_on": "2019-12-03T00:10:15+00:00"
  }
}