Skip to Content
ConnectFiles API

Files API

The Files API provides upload, metadata management, folder organization, and asset serving. On the Buildpad Engine backend, the Engine keeps the files on its own disk or in Amazon S3, and it can resize and convert images when it serves them. On the Supabase backend, the files are kept in Supabase Storage.

Endpoints

Send these requests to the Engine’s URL:

GET /api/files → 200 — list files POST /api/files → 201 — upload a file (multipart), create metadata (JSON), or register a signed upload GET /api/files/:id → 200 — get file metadata PATCH /api/files/:id → 200 — update file metadata or replace file (multipart) DELETE /api/files/:id → 204 — delete a file PATCH /api/files → 200 — batch update DELETE /api/files → 204 — batch delete POST /api/files/import → 200 — import from URL GET /api/files/:id/download → 200 — get a signed download URL GET /api/files/signed-url → 200 — get a signed URL to read a file without a session POST /api/files/signed-url → 201 — start a signed upload DELETE /api/files/signed-url → 204 — discard a signed upload that was not registered GET /api/files/assets/:id → 200 — serve file content, with optional image transforms GET /api/folders → 200 — list folders POST /api/folders → 201 — create folder PATCH /api/folders/:id → 200 — update folder DELETE /api/folders/:id → 204 — delete folder

The Studio serves /api/assets/:id on its own URL, for its own pages. On this backend, that route sends the request on to the Engine’s /api/files/assets/:id, with all of its query parameters.

GET /api/files → 200 — list files POST /api/files → 201 — upload a file (multipart) or create metadata (JSON) GET /api/files/:id → 200 — get file metadata PATCH /api/files/:id → 200 — update file metadata or replace file (multipart) DELETE /api/files/:id → 204 — delete a file PATCH /api/files → 200 — batch update DELETE /api/files → 204 — batch delete POST /api/files/import → 200 — import from URL GET /api/files/:id/download → 200 — get download URL GET /api/assets/:id → 200 — serve file asset (public URL) GET /api/folders → 200 — list folders POST /api/folders → 201 — create folder PATCH /api/folders/:id → 200 — update folder DELETE /api/folders/:id → 204 — delete folder

Storage

The Engine keeps the bytes of each file in one of two places. The operator sets the place with the Engine’s STORAGE_DRIVER:

STORAGE_DRIVERWhere the files are
local (the default)A folder on the Engine’s disk
s3A private Amazon S3 bucket, or an S3-compatible service

With S3 storage:

  • Only the Engine reads and writes the bucket. Clients never reach it. A download, a signed URL and a signed upload all go to the Engine’s own URL, and the Engine streams the bytes. The bucket needs no CORS rule and no public access.
  • Each deployment has its own folder. The Engine keeps every object under one key prefix, STORAGE_S3_ROOT, for example projects/<project id>/. Many deployments can share one bucket.
  • Credentials come from the server. On EC2, the Engine uses the instance role. Do not put access keys in the configuration.
  • A versioned bucket keeps old versions. A delete leaves an earlier version until the bucket’s lifecycle rule removes it.

On a Buildpad Cloud project with S3 storage, a backup keeps the files as they were when it was taken, and a restore puts them back with the data. Deleting the project deletes its files. Projects created before S3 storage was available keep their files on the project’s server.

For the Engine’s storage settings, see Run the Studio on the Buildpad Engine.

The files are kept in Supabase Storage buckets. The default bucket is files. The Studio reads and writes the buckets with the service-role key.

File Object

The File entity has the following fields. Fields marked * are always returned; others are null when not applicable.

FieldTypeDescription
id *stringUnique identifier (UUID)
storage *stringStorage bucket name (default: "files")
filename_diskstring | nullFilename as stored on disk
filename_download *stringOriginal filename for downloads
titlestring | nullDisplay title
typestring | nullMIME type
filesize *numberFile size in bytes (0 for metadata-only records)
widthnumber | nullImage width in pixels (not computed by server — set client-side)
heightnumber | nullImage height in pixels (not computed by server — set client-side)
durationnumber | nullDuration in seconds (video/audio)
charsetstring | nullCharacter encoding for text files
folderstring | nullParent folder ID
descriptionstring | nullDescription of the file
locationstring | nullLocation metadata
tagsstring[]Array of tags
metadataobjectArbitrary JSON metadata (EXIF, etc.)
embedstring | nullEmbed code/URL for external media
focal_point_xnumber | nullFocal point X coordinate for cropping
focal_point_ynumber | nullFocal point Y coordinate for cropping
tus_idstring | nullTUS resumable upload identifier
tus_dataobject | nullTUS upload data
uploaded_bystring | nullUser who uploaded the file
uploaded_onstring | nullUpload timestamp
created_on *stringRecord creation timestamp
modified_bystring | nullUser who last modified the file
modified_on *stringLast modification timestamp

Upload a File

Multipart Upload

Send a multipart/form-data request with the file binary and optional metadata:

curl -X POST https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -F "file=@/path/to/image.png" \ -F "title=My Image" \ -F "description=A sample image" \ -F "folder=<folder_id>" \ -F "storage=files"
Form fieldRequiredDescription
fileYes (multipart)The file binary
titleNoDisplay title
descriptionNoDescription text
folderNoParent folder ID
storageNoStorage bucket name (default: "files")

Response (201):

{ "data": { "id": "550e8400-e29b-41d4-a716-446655440000", "storage": "files", "filename_disk": "550e8400-e29b-41d4-a716-446655440000.png", "filename_download": "image.png", "title": "My Image", "description": "A sample image", "type": "image/png", "filesize": 204800, "width": null, "height": null, "folder": null, "tags": [], "metadata": {}, "uploaded_by": "<user_id>", "uploaded_on": "2024-01-15T10:30:00Z", "created_on": "2024-01-15T10:30:00Z", "modified_on": "2024-01-15T10:30:00Z" } }

width and height are not computed by the server. They will be null unless the client provides them on upload or updates them later via PATCH.

Upload Constraints

On the Engine, the Supabase bucket settings and the FILES_* variables below do not apply. The Engine refuses a signed upload that names a storage location that it does not have, with 400 and Storage bucket <name> is not allowed, and an upload that is larger than its limit, with 400 and File size exceeds maximum allowed (<n> bytes).

Size and type limits are read from the storage bucket, so you change them in Supabase Studio — Storage → the bucket → File size limit and Allowed MIME types — without redeploying. Supabase enforces them on the upload itself; DaaS reads the same values so an upload that would be refused is rejected up front, with a 400 in the standard error shape, before a signed URL is issued.

ConstraintWhere it is configuredFallback
Maximum upload sizeBucket File size limit (Studio)FILES_MAX_UPLOAD_SIZE, default 100 MB
Allowed MIME typesBucket Allowed MIME types (Studio)FILES_MIME_TYPE_ALLOW_LIST, default all types
Buckets signed uploads may targetFILES_STORAGE_BUCKET_ALLOW_LIST (comma-separated)files

A bucket field that is left unset — the default for a new bucket — falls back to the environment variable beside it. image/* style wildcards work in both.

Bucket configuration is cached for up to a minute, so a change made in Studio takes effect within that window.

The bucket allow-list is not bucket configuration and has no Studio equivalent: signed URLs are minted with service-role credentials, which can write to every bucket in the project, so this list is what confines the Files API to the buckets you intend it to use. It stays an environment variable deliberately.

Signed Direct Uploads

A signed upload sends the bytes in a separate request, so a large file does not have to fit in one API request. On the Engine, the upload URL is the Engine’s own URL (PUT /api/files/object/upload/sign/<location>/<key>?token=…), on local storage and on S3 storage alike. The Engine writes the bytes to the storage. The steps are the same as below. To replace the content of an existing file, add "replace": "<file id>" in step 1, and confirm with PATCH /api/files/<id> and the upload_token in place of POST /api/files.

Multipart uploads pass through the Next.js server, so they are bounded by its request body limit. To upload large files, send the bytes straight to Supabase Storage and register the metadata afterwards.

Step 1 — ask for a signed URL.

curl -X POST https://your-domain.com/api/files/signed-url \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{ "filename_download": "recording.mp4", "type": "video/mp4", "filesize": 734003200, "folder": "<folder_id>" }'

filename_download, type and filesize are required. The response carries an uploadUrl to PUT to and an uploadToken to quote in step 3. On the Engine, uploadUrl is an Engine URL. On the Supabase backend, the response looks like this:

{ "data": { "uploadUrl": "https://<project>.supabase.co/storage/v1/object/upload/sign/files/<id>.mp4?token=...", "token": "<supabase upload token>", "uploadToken": "<server-issued token>", "primaryKey": "<file_id>", "storagePath": "<folder_id>/<file_id>.mp4", "filenameDisk": "<file_id>.mp4", "storageBucket": "files" } }

Step 2 — PUT the bytes to uploadUrl. This request never touches the application server, so the body limit does not apply. The put token in the URL is the only credential that this request needs.

Step 3 — register the metadata, quoting upload_token:

curl -X POST https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{ "upload_token": "<server-issued token>", "filename_download": "recording.mp4", "title": "Recording" }'

id, filename_disk, storage, folder, type and filesize are taken from the token and from the stored object, not from this request body — size and type are read back from the storage, so a client cannot misreport what it uploaded or point a record at somebody else’s object. Any of these fields sent alongside upload_token are ignored.

A token is bound to the user it was issued to, expires after two hours, and is single-use: once POST /api/files has registered the upload, the token is spent.

If step 2 or step 3 fails, discard the orphaned object so it does not linger in the bucket:

curl -X DELETE https://your-domain.com/api/files/signed-url \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"upload_token": "<server-issued token>"}'

This needs only a valid token, not create permission on daas_files, so a permission change mid-upload cannot strand the object. It returns 204 whether or not the object was still there, and is refused once the upload has been registered.

JSON Mode (Metadata-Only)

Create a file record without uploading binary content. Useful for tracking external assets or placeholder entries:

curl -X POST https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{ "type": "image/png", "filename_download": "external-asset.png", "title": "External Asset", "storage": "files" }'

The type and filename_download fields are required in JSON mode. The response has the same shape as the multipart upload, with filesize: 0.

List Files

GET /api/files supports the following query parameters for filtering, sorting, and pagination:

ParamTypeDescription
limitnumberMaximum number of items to return
offsetnumberNumber of items to skip (for cursor-based pagination)
pagenumberPage number (alternative to offset)
searchstringFree-text search across title and filename
sortstringSort field(s), comma-separated. Prefix with - for descending (e.g. -uploaded_on)
fieldsstringComma-separated list of fields to return (e.g. id,title,filesize)
filterstring (JSON)JSON-encoded filter object (e.g. {"folder":{"_eq":"<id>"}})
metastringSet to filter_count to include metadata in the response

Example — list with pagination and metadata:

GET /api/files?limit=10&offset=0&meta=filter_count&sort=-uploaded_on

Response (200):

{ "data": [ { "id": "...", "title": "Image 1", "filesize": 204800, "..." }, { "id": "...", "title": "Image 2", "filesize": 102400, "..." } ], "meta": { "filter_count": 10, "total_count": 42 } }

When meta=filter_count is not passed, the meta key is omitted from the response.

Get File Metadata

Retrieve a single file’s metadata by ID:

GET /api/files/:id
ParamTypeDescription
fieldsstringComma-separated list of fields to return
metastringSet to filter_count to include count metadata

Response (200):

{ "data": { "id": "550e8400-e29b-41d4-a716-446655440000", "title": "My Image", "filename_download": "image.png", "type": "image/png", "filesize": 204800, "width": null, "height": null, "folder": null, "uploaded_by": "<user_id>", "uploaded_on": "2024-01-15T10:30:00Z" } }

Update File Metadata

JSON Body Update

Update metadata fields via JSON:

curl -X PATCH https://your-domain.com/api/files/<id> \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"title": "Updated Title", "description": "A better description", "tags": ["hero", "blog"]}'

Response (200):

{ "data": { "id": "<id>", "title": "Updated Title", "description": "A better description", "tags": ["hero", "blog"], "...": "..." } }

Multipart File Replacement

Replace the file binary for an existing file record using multipart form data:

curl -X PATCH https://your-domain.com/api/files/<id> \ -H "Authorization: Bearer <token>" \ -F "file=@/path/to/new-version.png"

The response has the same shape as the JSON update. The old file binary is replaced in storage; the file record’s filesize, type, and filename_download are updated automatically from the new file.

Delete a File

curl -X DELETE https://your-domain.com/api/files/<id> \ -H "Authorization: Bearer <token>"

Returns 204 No Content on success.

Serving Files

Use the asset endpoint to serve file content. The response is raw binary (not JSON) with appropriate Content-Type and Content-Disposition headers — suitable for <img src>, <video src>, or direct download links.

GET /api/files/assets/:id

The Engine serves a file to one of these callers:

  • A request with a session (Authorization: Bearer <access token>). The caller needs read on daas_files, and the file must be inside the row filter of that permission.
  • A signed URL (?token=…). An <img> or <video> element cannot send a header, so use a signed URL there. See Signed URLs.
  • A request with no credential, for a file that the public policy can read (a daas_access row with no role and no user). Name the tenant in the X-Tenant-Id header. Without the header, the Engine uses the host.

Every other request gets 401. The Engine checks the credential before it checks that the file exists.

Query paramDescription
downloadForces a file download (Content-Disposition: attachment)
tokenA signed token. See Signed URLs
width, height, fit, quality, format, withoutEnlargement, focal_point_x, focal_point_y, keyImage transforms. See Image Transforms

The Engine serves files with Cache-Control: private, max-age=31536000 (1 year), an ETag and Last-Modified. It answers If-None-Match with 304. It supports one Range per request, for video and audio seeking.

<img src="https://<engine-url>/api/files/assets/550e8400-e29b-41d4-a716-446655440000?token=<signed token>&key=system-medium-cover" alt="My Image" />
GET /api/assets/:id
Query paramDescription
downloadForces a file download (Content-Disposition: attachment)
widthResize image to this width. Supabase Storage must have image transformations available (a paid Supabase plan). If the transform fails, the original file is served
heightResize image to this height. The same condition applies

Assets are served with Cache-Control: private, max-age=31536000 (1 year), so only the browser keeps a copy. Updated files may not reflect immediately in all clients due to aggressive caching.

<img src="https://your-domain.com/api/assets/550e8400-e29b-41d4-a716-446655440000" alt="My Image" <!-- Authorization header must be set via fetch/XHR for protected assets --> />

All asset requests require a valid Authorization header. There is no unauthenticated asset serving — grant the requesting user’s policy read access on daas_files to allow access.

Image Transforms

The Engine can resize, crop and convert an image when it serves it. Add transform parameters to /api/files/assets/:id or to a signed URL:

GET /api/files/assets/<id>?width=300&height=200&fit=cover&quality=80 GET /api/files/assets/<id>?key=system-medium-cover
ParameterValues
width, height1–4096 pixels
fitcover, contain, inside, outside
quality1–100, for JPEG. The default is 80
formatauto, jpg, png, tiff. A request for webp or avif gets JPEG or PNG
withoutEnlargementtrue, false
focal_point_x, focal_point_yThe point that cover crops around, in pixels
keyA preset: one of the six system presets, such as system-small-cover, or a preset from the storage_asset_presets setting

The Engine refuses an image larger than 25 MiB or 6,000 pixels on a side with 400 ILLEGAL_ASSET_TRANSFORMATION, and a parameter that is not valid with 400 INVALID_QUERY. Other files, such as PDFs and videos, come back unchanged. See Image Transforms for the presets, the transform mode, the limits and the errors.

On the Supabase backend, /api/assets/:id takes width and height only. They work when Supabase Storage has image transformations available. Otherwise the original file is served.

Signed URLs

A signed URL lets a browser element, such as <img>, load a file with no Authorization header:

GET /api/files/signed-url?id=<file id>&expires=3600

The answer holds url, a path on the Engine: /api/files/assets/<id>?token=…. Add the Engine’s origin in front of it. Add transform parameters to it if necessary. expires is the lifetime in seconds, at most 604800 (seven days). The default is 3600.

The token is bound to the user who asked for it. Each time the URL is used, the Engine checks again that this user can read the file. The URL works only in the tenant where it was made.

On the Supabase backend, use Download File to get a temporary URL from Supabase Storage.

Download File

Get a signed download URL for a file. The response is JSON containing a temporary URL, not the file content itself.

GET /api/files/:id/download
Query paramTypeDefaultDescription
expires_innumber3600URL expiration time in seconds, at most 604800

Response (200):

{ "url": "/api/files/assets/<id>?token=...&download=1", "expires_in": 3600 }

On the Engine, url is a path on the Engine, on every storage location. Add the Engine’s origin in front of it.

{ "url": "https://<project>.supabase.co/storage/v1/object/sign/files/<filename_disk>?token=...", "expires_in": 3600 }

Import from URL

Download a remote file and store it in the file storage:

curl -X POST https://your-domain.com/api/files/import \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com/image.jpg", "data": {"title": "Imported Image"}}'

Returns 200 with the imported file data:

{ "data": { "id": "550e8400-...", "filename_download": "image.jpg", "title": "Imported Image", "...": "..." } }

Folder Organization

Files can be organized into hierarchical folders.

Create a Folder

curl -X POST https://your-domain.com/api/folders \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"name": "Blog Images", "parent": null}'

Response (201):

{ "data": { "id": "550e8400-e29b-41d4-a716-446655440000", "name": "Blog Images", "parent": null, "created_at": "2024-01-15T10:30:00Z", "updated_at": "2024-01-15T10:30:00Z" } }

List Folders

GET /api/folders

Response (200):

{ "data": [ { "id": "550e8400-...", "name": "Blog Images", "parent": null, "created_at": "2024-01-15T10:30:00Z", "updated_at": "2024-01-15T10:30:00Z" } ], "meta": { "filter_count": 1, "total_count": 1 } }

Update a Folder

curl -X PATCH https://your-domain.com/api/folders/<id> \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"name": "Renamed Folder"}'

Response (200):

{ "data": { "id": "550e8400-...", "name": "Renamed Folder", "parent": null, "created_at": "2024-01-15T10:30:00Z", "updated_at": "2024-01-15T11:00:00Z" } }

Setting a folder as its own parent (PATCH /api/folders/:id with "parent": "<same_id>") is rejected with a 400 error: A folder cannot be its own parent.

Delete a Folder

curl -X DELETE https://your-domain.com/api/folders/<id> \ -H "Authorization: Bearer <token>"

Returns 204 No Content on success.

A folder with subfolders or containing files cannot be deleted. Attempting to delete a non-empty folder returns a 400 error with code FOLDER_NOT_EMPTY. Delete all files and subfolders first.

Upload into a Folder

curl -X POST https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -F "file=@hero.jpg" \ -F "folder=<folder_id>"

Batch Operations

Batch Update

Update metadata for multiple files in a single request. Two formats are supported:

Keys format — apply the same update to multiple files:

curl -X PATCH https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"keys": ["id-1", "id-2", "id-3"], "data": {"title": "Bulk Updated"}}'

Array format — apply per-file updates:

curl -X PATCH https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '[ {"id": "id-1", "title": "New Title A"}, {"id": "id-2", "title": "New Title B", "description": "Updated desc"} ]'

Returns 200 with the updated file data.

Batch Delete

Batch delete accepts a JSON body with an array of file IDs (or an object with a keys array):

# Batch delete by ID list curl -X DELETE https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '["id-1", "id-2", "id-3"]' # Alternative: keys object curl -X DELETE https://your-domain.com/api/files \ -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"keys": ["id-1", "id-2"]}'

Returns 204 No Content.