Skip to main content
GET
Get Avatar

Endpoints

GET /api/avatar

Retrieves the authenticated user’s avatar image. Supports both local file storage and external URLs.

Response

Returns the avatar image file with appropriate content type headers. If avatar is an external URL, returns a 302 redirect.

POST /api/avatar

Uploads a new avatar image for the authenticated user. Old avatar is automatically deleted if it was a local file.

Request

file
required
Image file (multipart/form-data). Maximum size: 2MB. Allowed types: JPEG, PNG, WebP, GIF.

Response

string
Relative path to the uploaded avatar file
string
“Avatar uploaded successfully”

Implementation Details

Code Reference

Status Codes

OK
Success
Found
Redirect to external avatar URL (GET only)
Bad Request
No file provided, file too large, or invalid file type
Unauthorized
Missing or invalid authentication token
Not Found
Avatar not found (GET only)

File Requirements

  • Maximum size: 2MB
  • Allowed formats: JPEG, PNG, WebP, GIF
  • Storage: Local file system (user-specific directories)

Example Requests

Get Avatar

Upload Avatar

Environment Variables

string
Base path for avatar storage (default: src/avatars)

Security Notes

  • Old avatars are automatically deleted when uploading new ones
  • External URLs are supported (redirects to URL)
  • Files are stored in user-specific directories
  • Content-Type headers are set based on file extension
  • Cache-Control header set to 1 hour for GET requests

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Response

200 - image/*

Avatar image