Update the user's avatar image

PATCH /api/profile/updateavatar

The JWT token in the 'jwt' cookie is verified by the verifyJWT middleware. If valid, the user's ID is extracted from the token and added to request.body.userId. The uploadImage middleware then handles the file upload. Finally, the updateAvatar controller updates the user's avatar and returns the response.

multipart/form-data

Body Required

  • avatar string(binary)

Responses

  • 200 application/json

    Avatar updated successfully

    Hide response attribute Show response attribute object
    • avatar string
  • 400 text/plain

    Bad Request, no file uploaded

  • 401 text/plain

    Unauthorized, JWT cookie is missing

  • 403 text/plain

    Forbidden, JWT token is invalid

  • 404 text/plain

    User not found

  • 500 text/plain

    Internal server error

PATCH /api/profile/updateavatar
curl \
 --request PATCH 'http://localhost:xxxx/api/profile/updateavatar' \
 --cookie "jwt=$API_KEY" \
 --header "Content-Type: multipart/form-data" \
 --form "avatar=@file"
Response examples (200)
{
  "avatar": "src/assets/uploads/avatars/1726702800641EcoNex_A10.jpg"
}
Response examples (400)
需要上传图片
Response examples (401)
您未通过身份验证
Response examples (403)
无效的令牌
Response examples (404)
未找到用户
Response examples (500)
服务器内部错误