Import image resources into the system, supporting functions such as specifying resource categories, replacing existing resources, etc. This interface is mainly used for image upload and management in the background content management system.
Points to note
- This interface uses the POST method to submit data in form-data format
- An effective background import interface Token is required for authentication
- Supports specifying the image resource category ID
- Supports replacing existing image resources (specified by ID)
- Returns detailed information and access address of the image after upload
Request address
{ๅๅๅฐๅ}/attachment/upload?token={token}
Description:{ๅๅๅฐๅ}Replace it with your domain name, such ashttps://en.anqicms.com/attachment/upload?token={token}
Request Syntax
POST {ๅๅๅฐๅ}/attachment/upload?token={token}
Content-Type: multipart/form-data
Request parameters
GET parameters
| Field name |
Type |
Required |
Description |
| token |
string |
Is |
Token in the background content import interface function |
POST parameters
| Field name |
Type |
Required |
Description |
| category_id |
int |
No |
Image resource category ID |
| id |
int |
No |
Image resource ID, required if replacing an image |
| file |
File |
Is |
To upload the file resource |
Return parameters
| Field name |
Type |
Description |
| code |
int |
Error code |
| msg |
string |
Error description |
| data |
object |
result content |
data parameter
| Field name |
Type |
Description |
| id |
int |
Resource ID |
| file_name |
string |
Filename |
| file_location |
string |
File storage path |
| file_size |
int |
File size |
| file_md5 |
string |
file MD5 |
| width |
int |
image width |
| height |
int |
image height |
| category_id |
int |
Resource category ID |
| is_image |
int |
Is it an image, 1 is an image, 0 is not |
| Logo |
string |
Original |
| thumbnail |
string |
Thumbnail |
| created_time |
int |
Timestamp of creation |
| updated_time |
int |
update timestamp |
| status |
int |
Display Status |
Usage Example
Request example
curl -X POST \
'https://en.anqicms.com/attachment/upload?token=your_token_here' \
-H 'Content-Type: multipart/form-data' \
-F 'category_id=1' \
-F 'file=@/path/to/your/image.jpg'
Or use the form method:
POST /attachment/upload?token=your_token HTTP/1.1
Host: www.anqicms.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="category_id"
1
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="example.jpg"
Content-Type: image/jpeg
(file content)
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Response Example
{
"code": 0,
"data": {
"id": 213,
"created_time": 1662734332,
"updated_time": 1662734332,
"file_name": "example.jpg",
"file_location": "uploads/202209/09/5632dd13c746a365.webp",
"file_size": 9348,
"file_md5": "4fae2c295632dd13c746a3653227f93a",
"width": 160,
"height": 160,
"category_id": 1,
"is_image": 1,
"status": 1,
"logo": "https://en.anqicms.com/uploads/202209/09/5632dd13c746a365.webp",
"thumb": "https://en.anqicms.com/uploads/202209/09/thumb_5632dd13c746a365.webp"
},
"msg": ""
}
Example of error response
{
"code": -1,
"msg": "ๆไปถ็ฑปๅไธๅ
่ฎธไธไผ "
}
error code
| Error code |
Description |
| 0 |
OK |
| -1 |
Error, the reason is indicated in msg |
| 1001 |
Not logged in |
| 1002 |
Not authorized |
| 200 |
API request OK |