Media storage
How photos and videos are uploaded to Cloudflare R2, protected, served and deleted.
Uploaded images and videos live in the R2 bucket whyo-media, under u/<userId>/<uuid>.<ext>. Only the api worker touches the bucket.
Uploading
Start
POST /api/media/uploads with { contentType, size }. The worker checks the type and size and returns a key, plus an upload ID for big files.Send the file
PUT /api/media/object/<key>. Bigger: 10 MB parts to PUT /api/media/part/<key>?uploadId&part=N, then POST /api/media/complete. On failure the client calls POST /api/media/abort.Save the item
items.create with mediaKey. Convex refuses any key outside the user’s own u/<userId>/ prefix.| Kind | Types | Max |
|---|---|---|
| Image | JPEG, PNG, HEIC, HEIF, WebP, GIF | 25 MB |
| Video | MP4, MOV, WebM | 1 GB |
Serving
Convex decides who can see an item, so Convex signs the URL: /media/<key>?exp=…&sig=…, an HMAC-SHA256 over the key and expiry using MEDIA_SIGNING_SECRET. The worker only checks the signature. Links stay valid for at least a day, and the expiry is rounded to the day so query results and image caches stay stable.
Range requests are supported, so video players can seek.
Deleting
Deleting an item or a collection schedules a Convex action that calls POST /internal/media/delete on the worker, authenticated with the same secret. A worker on localhost isn’t reachable from Convex cloud, so in local development the files stay in local R2.