Create Product Image
Create a new product image.
HTTP Request
POST/api/products/:product_id/images
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| product_id | integer | Yes | The unique identifier of the product |
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| image | File | Yes | Image file to upload |
| alt_text | String | No | Alternative text for the image |
| is_primary | Boolean | No | Whether this should be the primary product image (default: false) |
| order | Integer | No | Display order of the image (default: 0) |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Upload a new product image
4with open('product_image.jpg', 'rb') as image_file:
5 files = {'image': image_file}
6 data = {
7 'alt_text': 'Product front view',
8 'is_primary': True,
9 'order': 1
10 }
11 response = requests.post(
12 'http://www.example.com/api/products/123/images',
13 files=files,
14 data=data,
15 headers={'Authorization': 'Token <your_api_key>'}
16 )
17print(response.json())
18
19# Upload additional image
20with open('product_side.jpg', 'rb') as image_file:
21 files = {'image': image_file}
22 data = {
23 'alt_text': 'Product side view',
24 'order': 2
25 }
26 response = requests.post(
27 'http://www.example.com/api/products/123/images',
28 files=files,
29 data=data,
30 headers={'Authorization': 'Token <your_api_key>'}
31 )
32print(response.json())1# Upload a new product image
2curl -X POST "http://www.example.com/api/products/123/images" \
3-H "Authorization: Token <your_api_key>" \
4-F "image=@product_image.jpg" \
5-F "alt_text=Product front view" \
6-F "is_primary=true" \
7-F "order=1"
8
9# Upload additional image
10curl -X POST "http://www.example.com/api/products/123/images" \
11-H "Authorization: Token <your_api_key>" \
12-F "image=@product_side.jpg" \
13-F "alt_text=Product side view" \
14-F "order=2"Status Codes
| Code | Description |
|---|---|
| 201 | Product image created successfully |
| 400 | Bad Request - Invalid input or file format |
| 401 | Unauthorized - Invalid or missing API key |
| 403 | Forbidden - Access denied |
| 404 | Not Found - Product not found |
| 413 | Payload Too Large - File size exceeds limit |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | integer | Unique identifier for the image |
| type | string | Image type (e.g., "JPEG", "PNG", "WEBP") |
| user | object | User who uploaded the image |
| name | string | Original filename of the image |
| f | string | File URL/path |
| size | integer | File size in bytes |
| description | string | Image description |
| width | integer | Image width in pixels |
| height | integer | Image height in pixels |
| human_readable_size | string | Human-readable file size (e.g., "2.5 MB") |
| mode | string | Image color mode (e.g., "RGB", "CMYK") |
| created_at | datetime | Image upload timestamp |
| updated_at | datetime | Image last update timestamp |
User Data Structure
| Field | Type | Description |
|---|---|---|
| id | integer | Unique ID of the user |
| username | string | Username of the user |
| full_name | string | Full name of the user |