Allow users to upload custom avatar images, supporting common image formats, used to update the avatar information in the user's personal profile.
Precautions
- This interface uses the POST method and requires data to be submitted in form-data format
- You need to log in as a user to call this interface
- The uploaded file must be in 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 the upload is successful
Request address
{域名地址}/api/user/avatar
Description:{域名地址}Need to replace it with your domain address, such ashttps://en.anqicms.com/api/user/avatar
Request syntax
POST {域名地址}/api/user/avatar
Content-Type: multipart/form-data
Request header
This interface also involves common request headers. For more information, please seeCommon Request Headers (Common Request Headers).
Request Parameters
| Field Name | Type | Required | Description |
|---|---|---|---|
| file | File | Yes | The avatar image resource to be uploaded, supporting common image formats |
Response Headers
This interface only involves public response headers. More information, please refer toCommon Request Headers (Common Request Headers).
Return parameters
| Field Name | Type | Description |
|---|---|---|
| code | integer | Error code |
| message | string | Error Description |
| data | object | Result Content |
data Parameter
| Field Name | Type | Description |
|---|---|---|
| avatar_url | string | The access address of the avatar image after upload |
Example Usage
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 | Unauthorized |
| 200 | API request OK |