Upload a cat image to the Cat Data API. This endpoint accepts multipart form data and stores the image file on the server.
Authentication
This endpoint requires Auth0 JWT authentication. Include the JWT token in the Authorization header:
Authorization: Bearer <your-token>
Request
The image file to upload. Must be a JPEG or PNG image.
Content Type
The request must use multipart/form-data encoding with a field name of file.
Allowed File Types
Files with other MIME types will be rejected with an error.
Response
The unique identifier assigned to the uploaded image in the database.
The filename under which the image was stored on the server. This includes a UUID prefix to ensure uniqueness.
Success Response (201)
{
"id": 42,
"filename": "a1b2c3d4-e5f6-7890-abcd-ef1234567890-cat.jpg"
}
Error Responses
400 Bad Request - Missing File
Returned when no file is provided in the request.
{
"error": "Missing file to upload"
}
400 Bad Request - Invalid File Type
Returned when the uploaded file is not a JPEG or PNG image.
{
"error": "Only JPG and PNG files are allowed."
}
401 Unauthorized
Returned when the JWT token is missing or invalid.
Example Request
curl -X POST https://api.example.com/api/upload \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." \
-F "file=@/path/to/cat.jpg"
Implementation Details
The endpoint uses Multer for handling multipart form data with the following configuration:
- Storage: Disk storage in the
images/ directory
- Filename: Generated using UUID v4 + original filename (e.g.,
uuid-cat.jpg)
- File Filter: Only allows
image/jpeg and image/png MIME types
- Field Name:
file (single file upload)
The uploaded file is stored in the filesystem and its filename is recorded in the database.