Skip to main content
urBackend handles file and image uploads for you. Upload a file and receive a public CDN URL you can use directly in your application. Base URL: https://api.ub.bitbros.in
All storage endpoints require your secret key (sk_live_...) in the x-api-key header. These operations should only be performed server-side.
All uploaded files are publicly accessible via the returned URL. Do not upload sensitive or private documents.

Upload a file

Uploads use a presigned URL three-step flow so the binary is sent directly to storage.

Step 1 — Request an upload URL

Endpoint: POST /api/storage/upload-request Request body (size in bytes):
Response:
This endpoint enforces the 10 MB max file size and checks available headroom against your plan’s project storage quota before the upload is confirmed. On the free tier, the default project storage limit is 20 MB.

Step 2 — Upload the binary to storage

Send a browser PUT request to signedUrl with the raw file contents and the correct Content-Type header.

Step 3 — Confirm the upload

Endpoint: POST /api/storage/upload-confirm Request body:
Response:
If the storage provider does not expose a public URL (for example, some external S3/R2 setups), the response returns url: null and includes a warning field explaining that a public URL is not available.
The confirm step verifies the object exists, checks the size matches, and then charges quota atomically.

Full browser example

SDK users (urbackend-sdk) do not need to change anything — client.storage.upload() uses this flow internally.

Required bucket CORS (S3/R2)

If you use AWS S3 or Cloudflare R2 with presigned browser uploads, configure bucket CORS so browser uploads to signedUrl can pass preflight. Required methods:
  • PUT
  • OPTIONS
  • GET
  • HEAD
Required AllowedHeaders (not ExposeHeaders) should include at least:
  • content-type — required for presigned PUT requests
  • content-length — typically safelisted, but some providers still require it to be allow-listed
Without these CORS rules, browser uploads can fail even when POST /api/storage/upload-request and POST /api/storage/upload-confirm are correct.

Delete a file

To delete a file, pass the path returned from the upload response. Endpoint: DELETE /api/storage/file
If the path is invalid or the file has already been removed, the API returns 404.

Limits

Troubleshooting

Ensure filename, contentType, and size are provided for the upload request, and that filePath and size are sent to the confirm endpoint.
The x-api-key header is missing or contains an invalid key. Check that you are using a valid key from your project dashboard.
The file exceeds the 10 MB per-file limit. Compress or resize the file before uploading.
If you use an external S3/R2 bucket, configure bucket CORS to allow PUT, OPTIONS, GET, and HEAD, and allow content-type and content-length headers from your client origin.