Data Access

Files & Assets

Upload, download, and manage files through the API.
The SDK does not include file upload or download methods — its HTTP client only supports JSON. Use fetch directly for file transfers, and the SDK's DirectusFile collection for metadata queries.

Upload a File

Send a POST request with multipart/form-data to the assets endpoint. The response returns the file IDs only.

// Upload with fetch — the SDK has no upload method
const form = new FormData();
form.append('file', fileInput.files[0]);

const uploadResponse = await fetch('https://example.monospace.io/api/blog/assets', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR_API_KEY',
  },
  body: form,
});

const { data } = await uploadResponse.json();
const fileId = data[0].id;

// Then query metadata via SDK
const fileMeta = await client.DirectusFile.readOne({
  key: fileId,
  fields: ['id', 'fileName', 'fileSize', 'mediaType', 'title', 'description'],
});
The upload response currently only returns file IDs. To get full metadata like fileName, fileSize, and mediaType, query the DirectusFile collection in a separate request. This limitation will likely be lifted in a future version.
Uploads are subject to a server-configured maximum file size (DIRECTUS_MAX_FILE_PAYLOAD_SIZE). Requests exceeding this limit receive 413 Payload Too Large.

Upload Multiple Files

Include multiple file fields in a single request. Each field with a filename is treated as a separate file upload.

curl -X POST https://example.monospace.io/api/blog/assets \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file1=@photo.jpg" \
  -F "file2=@document.pdf" \
  -F "file3=@report.csv"

Download a File

Retrieve a file by its ID. Files are served inline by default — images display in the browser, PDFs open in the viewer.

curl https://example.monospace.io/api/blog/assets/a1b2c3d4-5678-90ab-cdef-1234567890ab \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -o photo.jpg

You can include any filename after the file ID in the URL. This is useful for SEO — search engines and link previews will use the filename from the URL:

GET /api/blog/assets/a1b2c3d4-5678-90ab-cdef-1234567890ab/photo.jpg
If DIRECTUS_REDIRECT_ASSET_READ is enabled and the storage connector supports presigned URLs, the server returns a 307 Temporary Redirect to a presigned URL (60-second expiry). Otherwise, the file is streamed directly.

Force a File Download

By default, files are served inline (Content-Disposition: inline). Add ?download=true to force the browser to download the file as an attachment.

curl "https://example.monospace.io/api/blog/assets/a1b2c3d4-5678-90ab-cdef-1234567890ab?download=true" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -o photo.jpg

Read File Metadata

File metadata lives in the DirectusFile collection. System files and project files have separate endpoints.

Project Files

Project files are accessed through the standard items API at /api/{project}/items/DirectusFile. They include additional metadata fields beyond the base set.

const file = await client.DirectusFile.readOne({
  key: 'a1b2c3d4-5678-90ab-cdef-1234567890ab',
  fields: ['id', 'fileName', 'fileSize', 'mediaType', 'title', 'description', 'tags'],
});

System Files

System files (org logos, project logos, user avatars) have a dedicated endpoint at /api/system/files. These require authentication and only expose the base metadata fields.

curl https://example.monospace.io/api/system/files/a1b2c3d4-5678-90ab-cdef-1234567890ab \
  -H "Authorization: Bearer YOUR_API_KEY"

List Files

Project Files

List project file metadata using the standard items API. Supports filtering, sorting, and pagination.

const files = await client.DirectusFile.readMany({
  fields: ['id', 'fileName', 'fileSize', 'mediaType', 'title'],
});

System Files

curl "https://example.monospace.io/api/system/files?fields=id,fileName,fileSize,mediaType" \
  -H "Authorization: Bearer YOUR_API_KEY"

Delete a File

Delete a file and its metadata. Returns 204 No Content on success. This removes both the database record and the file from storage.

curl -X DELETE https://example.monospace.io/api/blog/assets/a1b2c3d4-5678-90ab-cdef-1234567890ab \
  -H "Authorization: Bearer YOUR_API_KEY"

File Metadata Fields

Project DirectusFile

FieldTypeNullableDescription
iduuidNoPrimary key
fileNamestringNoOriginal file name
fileSizebigintNoSize in bytes
mediaTypestringNoMIME type (auto-detected from extension if not provided)
titlestringYesUser-editable title
descriptionstringYesUser-editable description
tagsjsonYesUser-editable tags

System DirectusFile

FieldTypeNullableDescription
iduuidNoPrimary key
fileNamestringNoOriginal file name
fileSizebigintNoSize in bytes
mediaTypestringNoMIME type

Associate a File with an Item

Store the file's UUID in a relation field on your collection. Upload the file first, then reference its ID when creating or updating an item.

// 1. Upload with fetch
const form = new FormData();
form.append('file', fileInput.files[0]);

const uploadResponse = await fetch('https://example.monospace.io/api/blog/assets', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR_API_KEY',
  },
  body: form,
});

const { data: uploaded } = await uploadResponse.json();
const fileId = uploaded[0].id;

// 2. Create the article via SDK, connecting the file
const article = await client.Articles.createOne({
  data: {
    title: 'My Article',
    cover_image: {
      _connect: { key: { id: fileId } },
    },
  },
  fields: ['id', 'title', { cover_image: ['id', 'fileName'] }],
});
File fields are to-one relations to the DirectusFile collection. Use _connect to link an uploaded file — see Relational Data for all relational operations.

Endpoint Summary

OperationEndpointMethodResponse
Upload (project)/api/{project}/assetsPOST{ data: [{ id }] }
Upload (system)/api/system/assetsPOST{ data: [{ id }] }
Download/api/{project}/assets/{file_id}GETFile stream
Download (named)/api/{project}/assets/{file_id}/{file_name}GETFile stream
Delete (project)/api/{project}/assets/{file_id}DELETE204
Delete (system)/api/system/assets/{file_id}DELETE204
File metadata (system)/api/system/files/{file_id}GET{ data: {...} }
List files (system)/api/system/filesGET{ data: [...] }
File metadata (project)/api/{project}/items/DirectusFile/{id}GET{ data: {...} }
List files (project)/api/{project}/items/DirectusFileGET{ data: [...] }

See Also

Copyright © 2026