Upload media
POST/media/upload
Request a presigned upload URL for a media file. This is step 1 of the 3-step upload flow:
- POST /media/upload — Get a presigned upload URL (this endpoint)
- Upload your file to the returned
upload_urlusing the method specified inupload_method - POST /media/{id}/complete — Signal that the upload is finished
Upload methods by type:
- Images — POST multipart-form to Cloudflare Images (field name:
file) - Videos — PUT to R2 presigned URL with
Content-Typeheader - Documents — PUT to R2 presigned URL with
Content-Typeheader
Request Body Schema
POST /media/upload — Content-Type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
filename | string | Yes | Original filename with extension (max 255 chars). Example: photo.jpg |
content_type | string | Yes | MIME type of the file (see supported types below) |
size | integer | Yes | File size in bytes. Max 20MB for images/documents, 500MB for video. |
width | integer | No | Image/video width in pixels (used for aspect ratio calculation) |
height | integer | No | Image/video height in pixels (used for aspect ratio calculation) |
duration | number | No | Video duration in seconds |
Supported content types
| MIME Type | Category |
|---|---|
image/jpeg | Image |
image/png | Image |
image/gif | Image |
image/webp | Image |
image/heic | Image |
image/heif | Image |
video/mp4 | Video |
application/pdf | Document |
Request Example
{
"filename": "product-photo.jpg",
"content_type": "image/jpeg",
"size": 2048576
}
Response Example
201 — Upload URL generated
{
"data": {
"media_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"upload_url": "https://upload.imagedelivery.net/abc123/def456",
"upload_method": {
"method": "POST",
"content_type": "multipart/form-data",
"field_name": "file"
},
"provider": "cloudflare_images",
"expires_in": 3600,
"max_size": 20971520,
"next_step": "Upload your file to upload_url, then call POST /media/{media_id}/complete to finalize."
},
"error": null,
"meta": {
"request_id": "a1b2c3d4",
"timestamp": "2026-04-10T12:00:00.000Z"
}
}
Response fields
| Field | Type | Description |
|---|---|---|
media_id | string (UUID) | Use this ID when calling POST /media/{id}/complete and when attaching to posts via media_ids |
upload_url | string | Presigned URL to upload your file to |
upload_method.method | string | HTTP method to use: PUT or POST |
upload_method.content_type | string | Content-Type header to set |
upload_method.field_name | string | Form field name (only for POST/multipart uploads) |
upload_method.headers | object | Headers to include with the upload request (for PUT uploads) |
provider | string | Storage provider: cloudflare_images or r2 |
expires_in | integer | Seconds until the upload URL expires |
max_size | integer | Maximum file size in bytes |
next_step | string | Instructions for what to do after uploading |
Request
Responses
- 201
- 400
- 401
- 429
Upload URL generated
Invalid request parameters
Missing or invalid API key
Rate limit exceeded
Response Headers
X-RateLimit-Limit
Request limit per window
X-RateLimit-Remaining
Remaining requests in current window
X-RateLimit-Reset
Unix timestamp when the window resets
Retry-After
Seconds to wait before retrying