Import Image Resources Interface

Import image resources into the system, supporting features such as specifying resource categories, replacing existing resources, etc. This interface is mainly used for the image upload and management of the background content management system.

Precautions

  • This interface uses the POST method to submit data in form-data format
  • Need to provide a valid backend import interface Token for authentication
  • Support for specifying the image resource category ID
  • Support for replacing existing image resources (specified by ID)
  • Returns the detailed information and access address of the image after successful upload

Request address

{域名地址}/attachment/upload?token={token}

Description:{域名地址}Need to replace it with your domain address, such ashttps://en.anqicms.com/attachment/upload?token={token}

Request syntax

POST {域名地址}/attachment/upload?token={token}
Content-Type: multipart/form-data

Request Parameters

GET Parameter

Field Name Type Required Description
token string Yes Token in the background content import interface function

POST parameters

Field Name Type Required Description
category_id integer No Image resource category ID
id integer No Image resource ID, required if replacing an image
file File Yes File resource to be uploaded

Return parameters

Field Name Type Description
code integer Error code
message string Error Description
data object Result Content

data Parameter

Field Name Type Description
id integer Resource ID
file_name string English version: File name
file_location string File storage path
file_size integer File size
file_md5 string File MD5
width integer Image Width
height integer Image Height
category_id integer Resource Category ID
is_image integer Whether it is an image, 1 is an image, 0 is not
Logo string Original image
Thumbnail string Thumbnail
created_time integer Creation Timestamp
updated_time integer update timestamp
status integer Show Status

Example Usage

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": ""
}

Error response example

{
  "code": -1,
  "msg": "文件类型不允许上传"
}

Error Code

Error code Description
0 OK
-1 Error, the reason is indicated in msg
1001 Not logged in
1002 Unauthorized
200 API request OK