Media APIs
Image upload and management
Media APIs
Endpoints for uploading and managing images in R2 storage.
Base URL: https://ycwadelaide.adenmgb.com
Authentication: All endpoints require Authorization: Bearer <token> header.
POST /api/staff/upload/image
Upload an image file to R2 storage and get back a URL for use in content.
Headers:
Request Body (FormData):
Success Response (200 OK):
If duplicate image detected:
Error Responses:
- 400 Bad Request - No file provided
- 400 Bad Request - Invalid file type
- 401 Unauthorized - Not authenticated
- 500 Internal Server Error - Upload failed
Important Notes:
- Allowed file types:
image/jpeg,image/jpg,image/png,image/webp,image/gif - Files are automatically deduplicated by SHA-256 hash
- Returns existing URL if duplicate detected (saves storage space)
- Images are stored in R2 bucket with CDN access
- Use the returned
urlinimageUrlorcoverImageUrlfields - Filename is auto-generated with timestamp and random string
Example Request (JavaScript/Fetch):
Example Request (cURL):
GET /api/staff/images
List all uploaded images from R2 storage for selection/reuse.
Headers:
Success Response (200 OK):
Error Responses:
- 401 Unauthorized - Not authenticated
- 500 Internal Server Error - Failed to list images
Use Cases:
- Browse uploaded images
- Select existing images for content
- Image library/gallery view
- Reuse previously uploaded images
- Check image metadata (size, upload date)
Notes:
- Returns all images in R2 bucket
- Results include metadata (size in bytes, upload date)
- Use
urlfield to reference images in content - Consider implementing pagination for large image libraries
- Results are ordered by upload date (newest first)
Example - Use image URL in content:
Image Serving
Images are served via the /api/images/ path:
Notes:
- Images are served directly from R2 bucket
- CDN caching enabled for performance
- No authentication required for image URLs
- Images are publicly accessible once uploaded
Best Practices
- Compress Images - Compress images before upload for better performance
- Validate Client-Side - Check file type and size before upload
- Show Progress - Display upload progress indicator
- Handle Duplicates - Check
duplicateflag and inform user - Use Appropriate Sizes - Upload appropriately sized images:
- Featured images: 1200x630px
- Content images: 800-1200px wide
- Thumbnails: 400x400px
Related Guides
- Content APIs - Using images in content
- Public APIs - Public image access