Skip to main content
POST
/
api
/
user
/
profile-photo
Upload Profile Photo
curl --request POST \
  --url https://api.example.com/api/user/profile-photo \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: <content-type>' \
  --header 'x-api-key: <x-api-key>' \
  --data '{}'
{
  "success": true,
  "message": "Profile photo updated successfully",
  "data": {
    "fieldCount": 0,
    "affectedRows": 1,
    "insertId": 0,
    "info": "Rows matched: 1  Changed: 1  Warnings: 0",
    "serverStatus": 2,
    "warningStatus": 0,
    "changedRows": 1
  }
}
Uploads a profile photo for the authenticated user.

Authentication

This endpoint requires both API key and JWT authentication.

Required Headers

x-api-key
string
required
Your API key for accessing the API
Authorization
string
required
Bearer token in the format: Bearer <token>
Content-Type
string
required
Must be multipart/form-data

Request Body

This endpoint accepts form-data with a file upload.
photo
file
required
Profile photo file to uploadAllowed formats: JPEG, PNG, GIF, JPG, BMP, WEBPMaximum size: 5MB

Response

success
boolean
Indicates if the request was successful
message
string
Response message indicating the result of the upload
data
object
Contains information about the database update operation

Example Request

cURL
curl --request POST \
  --url https://api.example.com/api/user/profile-photo \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' \
  --header 'x-api-key: your_api_key_here' \
  --form 'photo=@/path/to/profile-photo.jpg'
JavaScript (Fetch)
const formData = new FormData();
formData.append('photo', fileInput.files[0]);

fetch('https://api.example.com/api/user/profile-photo', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
    'x-api-key': 'your_api_key_here'
  },
  body: formData
})
.then(response => response.json())
.then(data => console.log(data));

Example Response

{
  "success": true,
  "message": "Profile photo updated successfully",
  "data": {
    "fieldCount": 0,
    "affectedRows": 1,
    "insertId": 0,
    "info": "Rows matched: 1  Changed: 1  Warnings: 0",
    "serverStatus": 2,
    "warningStatus": 0,
    "changedRows": 1
  }
}

Error Responses

{
  "success": false,
  "message": "photo is required"
}

File Upload Details

  • Field name: photo (must match the multipart form field name)
  • Allowed MIME types: image/jpeg, image/png, image/gif, image/jpg, image/bmp, image/webp
  • Maximum file size: 5MB (5,242,880 bytes)
  • Storage location: Files are stored in uploads/profile-photo/ directory
  • Filename format: {timestamp}-{random}.{extension} (e.g., 1709123456789-123456789.jpg)
  • URL format: The photo URL stored in the database follows the pattern: uploads/profile-photo/{filename}

Notes

  • The uploaded file is automatically validated for type and size
  • The profile photo URL is stored in the profile_photo field of the user record
  • Previous profile photos are not automatically deleted - consider implementing cleanup logic if needed
  • The photo can be accessed via the static file endpoint: /uploads/profile-photo/{filename}

Build docs developers (and LLMs) love