Function upload_avatar

Source
pub async fn upload_avatar(
    __arg0: State<AppState>,
    __arg1: Path<i64>,
    multipart: Multipart,
) -> impl IntoResponse
Expand description

PUT /api/users/{user_id}/avatar

Upload a avatar for a user. Only admins may upload avatars for other users.

§Path Parameters

  • id - The ID of the user to upload the avatar for

§Request (multipart/form-data)

  • file (required): The image file to upload.
    Allowed types: image/jpeg, image/png, image/gif
    Max size: 2MB

§Responses

  • 200 OK

    {
      "success": true,
      "data": {
        "profile_picture_path": "user_1/avatar.jpg"
      },
      "message": "Avatar uploaded for user."
    }
  • 400 Bad Request

    • No file uploaded
    • File too large
    • File type not supported
  • 403 Forbidden

    {
      "success": false,
      "message": "Only admins may upload avatars for other users"
    }
  • 404 Not Found

    {
      "success": false,
      "message": "User not found."
    }
  • 500 Internal Server Error

    {
      "success": false,
      "message": "Database error."
    }