Function upload_profile_picture

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

POST /api/auth/upload-profile-picture

Upload a profile picture for the authenticated user.

This endpoint accepts a multipart/form-data request containing a single file field named file. Only JPEG, PNG, and GIF images are allowed, and the file size must not exceed 2MB. The uploaded file is stored in a user-specific directory, and the user’s profile in the database is updated with the relative path to the profile picture.

§Request (multipart/form-data)

  • file: The image file to upload (JPEG, PNG, or GIF, max 2MB)

§Responses

  • 200 OK

    {
      "success": true,
      "data": {
        "profile_picture_path": "user_1/avatar.jpg"
      },
      "message": "Profile picture uploaded."
    }
  • 400 Bad Request (invalid file type, too large, or missing file)

    {
      "success": false,
      "message": "File type not supported."
    }

    or

    {
      "success": false,
      "message": "File too large."
    }

    or

    {
      "success": false,
      "message": "No file uploaded."
    }
  • 500 Internal Server Error

    {
      "success": false,
      "message": "Database error: detailed error here"
    }