Storage API
Cocobase provides a secure and scalable file storage system with automatic S3 integration. You can upload files directly or alongside your documents and user profiles.Overview
Key features:- Direct Uploads: Upload files to specific paths.
- Integrated Uploads: Upload files when creating or updating documents.
- User Files: Support for user avatars and cover photos.
- S3-Backed: High-performance cloud storage for all file types.
- Public URLs: Automatically generated CDN-ready URLs.
File Upload
Upload a file usingmultipart/form-data.
Endpoint
POST /storage/upload
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
file | file | Yes | The file to upload |
path | string | No | Target folder/path (e.g., avatars/) |
Example
- cURL
- JavaScript
Management Endpoints
List Files
Retrieve all files in a specific directory.- Endpoint:
GET /storage/list - Query Params:
path,limit,offset
Delete File
- Endpoint:
DELETE /storage/file/{id}
Storage Info
Get project-wide storage usage statistics.- Endpoint:
GET /storage/info
Uploading with Users & Documents
Cocobase allows you to upload files as part of a document or user update. This is the recommended way to handle avatars and media attachments.User Profile Update with Avatar
Document Creation with Files
Best Practices
- Validation: Always validate file types and sizes on the client side before uploading.
- Organization: Use descriptive paths (e.g.,
/users/{id}/avatars/) to keep storage organized. - Optimizations: Compress images before upload to save space and improve load times.
- Error Handling: Handle 413 (Payload Too Large) and storage limit errors gracefully.
Storage Limits
| Tier | Max File Size | Total Storage |
|---|---|---|
| Free | 10 MB | 1 GB |
| Pro | 100 MB | 100 GB |
| Enterprise | 1 GB | Unlimited |
Supported Types
- Images:
.jpg,.png,.webp,.gif,.svg - Docs:
.pdf,.docx,.txt,.csv - Video:
.mp4,.mov,.webm - Archives:
.zip,.tar.gz
