Upload an image file for use with products. This endpoint handles file uploads and returns the uploaded file information.
Authentication
This endpoint requires authentication with the admin role.
Request
This endpoint accepts multipart/form-data for file uploads.
The image file to upload. Must be provided as a file in the multipart form data with the field name file.
Response
The response structure depends on the upload service implementation. Typically includes:
The name of the uploaded file
The URL or path where the file can be accessed
The size of the uploaded file in bytes
curl -X POST https://api.example.com/products/upload-image \
-H "Authorization: Bearer YOUR_TOKEN" \
-F "file=@/path/to/espresso.jpg"
{
"filename": "espresso-1234567890.jpg",
"url": "/uploads/espresso-1234567890.jpg",
"size": 245678
}
Error message describing what went wrong
{
"statusCode": 400,
"message": "The image is required",
"error": "Bad Request"
}
Usage Workflow
Upload Image
First, upload the image file using this endpoint. Save the returned filename or URL.
Create/Update Product
Use the returned filename/URL in the image field when creating or updating a product.{
"name": "Espresso Coffee",
"price": 12.99,
"image": "espresso-1234567890.jpg",
"inventory": 50,
"categoryId": 1
}
File Requirements
- Field name must be
file
- Accepted formats depend on server configuration (typically JPG, PNG, GIF, WebP)
- Maximum file size depends on server configuration
- Images are typically stored with a unique filename to prevent conflicts