Skip to main content
POST
/
api
/
user
/
upload
Upload User Avatar
curl --request POST \
  --url https://api.example.com/api/user/upload \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '{}'
{
  "code": 123,
  "status": "<string>",
  "image": "<string>",
  "message": "<string>",
  "errors": {}
}

Endpoint

POST /api/user/upload
This endpoint allows authenticated users to upload an avatar image. The image is stored in the users storage disk with a timestamped filename.

Authentication

Authorization
string
required
JWT token for authenticating the user (validated by ApiAuthMiddleware)Example: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
This endpoint requires authentication via the ApiAuthMiddleware. Requests without a valid JWT token will be rejected.

Request Body

file0
file
required
The image file to uploadContent-Type: multipart/form-dataAccepted formats: jpg, jpeg, png, gifValidation: Must be a valid image file

Response

code
integer
HTTP status code (200 for success, 400 for error)
status
string
Status of the upload: success or error
image
string
The filename of the uploaded image (only present on success)Format: {timestamp}{original_filename}Example: 1672934567avatar.png
message
string
Error message (only present when status is error)
errors
object
Validation errors (only present when validation fails)

Request Example

curl -X POST "https://api.example.com/api/user/upload" \
  -H "Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." \
  -F "file0=@/path/to/avatar.png"

Response Examples

{
  "code": 200,
  "status": "success",
  "image": "1672934567avatar.png"
}

Validation Rules

The endpoint validates the following rules:
  • file0: Required field
  • Must be a valid image file
  • Allowed mime types: jpg, jpeg, png, gif
  • Must pass Laravel’s image validation

Storage Details

Images are stored in the users storage disk. The filename format is {timestamp}{original_filename} where timestamp is a Unix timestamp ensuring unique filenames.

Retrieving Uploaded Avatars

After uploading an avatar, you can retrieve it using the following endpoint:

GET /api/user/avatar/

Retrieve an uploaded avatar image by its filename.

Path Parameters

filename
string
required
The filename of the avatar image returned from the upload endpoint

Request Example

cURL
curl -X GET "https://api.example.com/api/user/avatar/1672934567avatar.png" \
  --output avatar.png

Response

  • Success (200): Returns the image file with appropriate content type
  • Not Found (404): Returns JSON error if image doesn’t exist
Error Response (404)
{
  "code": 404,
  "status": "error",
  "message": "La imagen no existe."
}
The getImage endpoint does not require authentication and can be used to display user avatars publicly.

Build docs developers (and LLMs) love