Allow users to upload custom avatar images, supporting common image formats, used to update the avatar information in the user's personal profile.
Points to note
- The interface uses the POST method and requires data to be submitted in form-data format
- You need to log in as a user before you can call this interface
- The uploaded file must be an image format (such as JPG, PNG, WEBP, etc.)
- The file size and format may be limited, depending on the system configuration
- The avatar of the currently logged-in user will be automatically updated after successful upload
Request address
{域名地址}/api/user/avatar
Description:{域名地址}Replace it with your domain name, such ashttps://en.anqicms.com/api/user/avatar
Request Syntax
POST {域名地址}/api/user/avatar
Content-Type: multipart/form-data
Request Headers
This interface also involves common request headers. For more information, please refer toCommon Request Headers (Common Request Headers).
Request parameters
| Field name | Type | Required | Description |
|---|---|---|---|
| file | File | Is | The avatar image resource to be uploaded, supporting common image formats |
Response header
This interface only involves public response headers. For more information, please refer toCommon Request Headers (Common Request Headers).
Return parameters
| Field name | Type | Description |
|---|---|---|
| code | int | Error code |
| msg | string | Error description |
| data | object | result content |
data parameter
| Field name | Type | Description |
|---|---|---|
| avatar_url | string | address of the avatar image uploaded |
Usage Example
Request example
POST /api/user/avatar HTTP/1.1
Host: www.anqicms.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="avatar.jpg"
Content-Type: image/jpeg
<二进制图片数据>
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Response Example
{
"code": 0,
"msg": "上传成功",
"data": {
"avatar_url": "https://en.anqicms.com/uploads/user/1.webp"
}
}
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 |