Overview
ThinkEx provides flexible file upload capabilities with support for both Supabase Storage and local filesystem storage. The system includes:- Direct-to-storage uploads (bypassing serverless limits)
- Signed URL generation for large files
- Automatic fallback for small files
- Support for files up to 200MB
Upload Methods
Direct Upload (Recommended)
For large files, use the two-step direct upload flow to bypass the 4.5MB serverless function body limit.Step 1: Request Signed URL
Original filename (will be sanitized and made unique)
MIME type of the file (e.g.,
application/pdf, image/png)Storage mode:
supabase or localSigned upload URL (Supabase mode only, valid for 5 minutes)
Public URL for accessing the file after upload
Storage path/filename (unique)
Step 2: Upload to Signed URL
Simple Upload
For files under 50MB, you can use the simple upload endpoint:File to upload (max 50MB)
Whether the upload succeeded
Public URL of the uploaded file
Generated unique filename
Client SDK
The recommended way to upload files from the client is using theuploadFileDirect utility:
- Validates file size (200MB limit)
- Requests a signed URL
- Falls back to simple upload for local storage
- Falls back to
/api/upload-fileif direct upload fails for small files
Storage Configuration
Configure storage backend via environment variables:Supabase Storage (Default)
- Files stored in
file-uploadbucket - Requires Supabase project with storage enabled
- Bucket must allow public reads or use signed URLs
Local Storage
- Files stored in local filesystem
- Directory created automatically if it doesn’t exist
- Files accessible via
/api/files/:filename
File Naming
All uploaded files are automatically renamed with a unique identifier:1709123456789-abc123def45-my_document.pdf
- Special characters replaced with underscores
- Timestamp prevents conflicts
- Random string adds extra uniqueness
Error Responses
Error message describing what went wrong
Additional error details (when available)
Common Errors
| Status | Error | Solution |
|---|---|---|
| 401 | Unauthorized | User must be authenticated |
| 400 | No file provided | Include file in form data |
| 400 | File size exceeds limit | Reduce file size or split into multiple uploads |
| 500 | Server configuration error | Check environment variables |
| 500 | Failed to upload file | Check storage backend connectivity |
Rate Limits
The upload endpoints have the following limits:- Max file size: 50MB (simple upload), 200MB (direct upload)
- Max duration: 30 seconds (simple upload), 10 seconds (signed URL generation)
- Concurrent uploads: Limited by client
Security
- All endpoints require authentication via Better Auth session
- File URLs are validated to prevent SSRF attacks
- Filenames are sanitized to prevent path traversal
- Supabase service role key never exposed to client
- Signed URLs expire after 5 minutes
See Also
- PDF Processing - OCR and text extraction
- Storage Configuration - Backend setup details