/api/records/v1
Upload Files with Records
Files are uploaded as part of record creation or updates using multipart form data.Create Record with File
POST /api/records/v1/{name}
Path Parameters
string
required
Record API name
Request Format
Usemultipart/form-data content type with both data fields and file fields:
File Column Types
TrailBase supports two file column types:- Single File (
FileUpload): One file per field - Multiple Files (
FileUploads): Array of files per field
Response
Update Record with File
PATCH /api/records/v1/{name}/{record}
File Replacement
When updating a file column:- Old file is marked for deletion
- New file is uploaded
- Record is updated with new file metadata
- Old file is deleted asynchronously
If the update fails, newly uploaded files are automatically cleaned up to prevent orphaned files in storage.
Download Single File
Download a file from a single-file column.GET /api/records/v1/{name}/{record}/file/{column_name}
Path Parameters
string
required
Record API name
string
required
Record ID
string
required
Name of the file column
Response
Returns the file content with appropriate headers:Download File from Array
Download a specific file from a multi-file column.GET /api/records/v1/{name}/{record}/files/{column_name}/{file_name}
Path Parameters
string
required
Record API name
string
required
Record ID
string
required
Name of the file array column
string
required
Original filename from the file metadata
File Metadata
When you create a record with files, the file column stores metadata:File Column Schema
Single File Column
Multiple Files Column
Storage Configuration
TrailBase supports multiple storage backends:Local Filesystem
Amazon S3
Google Cloud Storage
Azure Blob Storage
File Upload Constraints
File Size Limits
Configure maximum file size in your server settings:Allowed File Types
Implement CHECK constraints or access rules to restrict file types:Access Control
File downloads respect record-level access control:File Lifecycle
Upload Flow
- Client sends multipart request with file(s)
- TrailBase validates file metadata
- File uploaded to object storage
- Record created/updated with file metadata
- On success, file is committed
- On failure, file is cleaned up
Delete Flow
- Record deleted (or file column updated)
- File marked for deletion in
_file_deletionstable - Asynchronous cleanup process deletes file from storage
- Deletion retried up to 10 times on failure
- Abandoned after 10 failed attempts (logged as error)
Orphaned File Prevention
TrailBase uses transactional file management:- Files uploaded during failed operations are cleaned up
- Database triggers track files for deletion
- Background jobs handle async file cleanup
- Failed deletions are retried automatically
JavaScript/TypeScript Client
Upload File
Upload Multiple Files
Download File
Update File
React File Upload Component
Image Optimization
For image files, consider implementing client-side compression:Direct File URLs
File download URLs are deterministic based on the record ID and column name:File Metadata API
File metadata is stored directly in the record. Fetch it via the standard read endpoint:Best Practices
- Validate files client-side before upload to improve UX
- Compress images before upload to reduce bandwidth and storage
- Use appropriate content types for accurate file handling
- Implement progress indicators for large file uploads
- Handle upload failures gracefully with retry logic
- Clean up blob URLs after use to prevent memory leaks
- Set reasonable file size limits based on your use case
- Use signed URLs for public file access instead of embedding tokens
- Consider CDN integration for frequently accessed files
- Monitor storage usage and implement cleanup policies
Troubleshooting
Upload Fails with 413 Payload Too Large
Increase the server’s max upload size:Files Not Deleted After Record Deletion
- Check
_file_deletionstable for pending deletions - Verify object storage credentials
- Review server logs for deletion errors
- Files are retried up to 10 times before being abandoned
Cannot Download File (403 Forbidden)
- Verify user has read access to the record
- Check row-level access rules
- Confirm file column is not excluded from API
- Ensure auth token is valid and not expired
File Upload Succeeds but Record Creation Fails
Files are automatically cleaned up when the transaction fails. This is expected behavior to prevent orphaned files.Error Responses
Bad Request
Invalid file format, missing required fields, or constraint violation
Forbidden
Access denied by ACL or row-level access rule
Not Found
Record, column, or file not found
Method Not Allowed
API doesn’t support file operations or wrong HTTP method
Payload Too Large
File exceeds maximum upload size
Internal Server Error
Storage backend error or unexpected server failure