File Uploads
Prestarts and activities support file attachments (photos, documents, PDFs). Files are uploaded via multipart form data and stored on the server filesystem.
Upload Flow
- User selects a file using the file input
- Frontend creates a
FormDataobject with the file - Server action sends
POST /prestarts/{prestartId}/files(or.../activities/{activityId}/files) - Go handler:
- Parses the multipart form (max 32MB)
- Creates the storage directory:
./uploads/prestarts/{orgId}/{prestartId|activityId}/ - Writes the file to disk
- Inserts metadata into
prestart_filestable
- Returns the file record with
file_urlfor display
Delete File
- User clicks delete on a file
- Server action calls
DELETE /files/{fileId} - Go handler soft-deletes the
prestart_filesrow - The physical file remains on disk (can be cleaned up by a future maintenance task)
File Serving
Files are served via the existing static file server in main.go at /uploads/*. The prestart file handler builds the URL as:
/uploads/prestarts/{orgId}/{parentId}/{filename}Security
- Only the prestart creator or an admin can upload/delete files
- Files are associated with
org_idfor tenant isolation - The CHECK constraint ensures every file has at least one parent (
prestart_idoractivity_id)
Key Files
| File | Purpose |
|---|---|
backend/db/queries/prestart_files.sql | 3 file queries |
backend/api/internal/prestart/service.go | File upload/delete logic |
backend/api/internal/prestart/handler.go | File HTTP handlers |
apps/web/src/actions/prestarts.ts | uploadPrestartFile, uploadActivityFile, deletePrestartFile |