TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/S4nti4goCoder/cloudsyncpro/llms.txt
Use this file to discover all available pages before exploring further.
upload-file Edge Function validates the caller’s identity and workspace permissions, then generates a presigned Cloudflare R2 PUT URL. The client uploads directly to R2—bytes never route through Supabase—and then registers the file in Postgres using the returned r2Key.
Endpoint
Authentication
Every request must include both headers:| Header | Value |
|---|---|
Authorization | Bearer <access_token> — the Supabase session token |
apikey | Your Supabase anonymous key |
supabase.auth.getUser() to verify the token before proceeding. Requests without a valid session are rejected with 401.
Request body
Original name of the file. Non-alphanumeric characters (except
., _, -) are replaced with - when building the R2 object key.MIME type of the file (e.g.
image/png, application/pdf). Passed as ContentType to the presigned PutObject command.Size of the file in bytes. Passed as
ContentLength to the presigned PutObject command.UUID of the workspace the file belongs to. The function calls
has_workspace_edit_permission via RPC to confirm the caller has at least editor-level access.UUID of the destination folder, or
null to place the file at the workspace root. Defaults to "root" in the generated R2 key when null.Response
A successful200 response returns:
A signed R2 URL valid for 3600 seconds (1 hour). Issue an HTTP
PUT to this URL with the file bytes, Content-Type, and Content-Length headers to complete the upload.The object key under which the file is stored in R2. Format:
{workspaceId}/{folderId|"root"}/{timestamp}-{sanitizedFileName}. Store this in Postgres when registering the file record.The full public URL to the uploaded object, composed from
R2_PUBLIC_URL and the r2Key. Available immediately after the PUT succeeds if the bucket is public.Error responses
| Status | Error message | Cause |
|---|---|---|
400 | Missing required fields | fileName, fileType, or workspaceId is absent from the request body |
401 | Missing Authorization | No Authorization header was sent |
401 | Unauthorized | The bearer token is invalid or expired |
403 | Forbidden: insufficient role | The authenticated user does not have edit permission in the specified workspace |
500 | Permission check failed | The has_workspace_edit_permission RPC returned an error |
500 | Internal server error | An unexpected error occurred (e.g. R2 signing failure) |
Examples
The function calls the
has_workspace_edit_permission Postgres RPC before issuing the presigned URL. Users with a viewer role will receive a 403 even if they supply a valid session token. Only editor, admin, and superadmin roles can upload files.