Endpoint
This endpoint allows authenticated users to upload an avatar image. The image is stored in the users storage disk with a timestamped filename.
Authentication
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
The image file to upload Content-Type : multipart/form-dataAccepted formats : jpg, jpeg, png, gifValidation : Must be a valid image file
Response
HTTP status code (200 for success, 400 for error)
Status of the upload: success or error
The filename of the uploaded image (only present on success) Format: {timestamp}{original_filename} Example: 1672934567avatar.png
Error message (only present when status is error)
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
Success (200)
Validation Error (400)
Missing File (400)
{
"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
The filename of the avatar image returned from the upload endpoint
Request Example
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
{
"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.