Skip to main content
POST
/
products
/
upload-image
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
}
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.
file
file
required
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:
filename
string
The name of the uploaded file
url
string
The URL or path where the file can be accessed
size
number
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
}

Errors

statusCode
integer
HTTP status code
message
string
Error message describing what went wrong
{
  "statusCode": 400,
  "message": "The image is required",
  "error": "Bad Request"
}

Usage Workflow

1

Upload Image

First, upload the image file using this endpoint. Save the returned filename or URL.
2

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

Build docs developers (and LLMs) love