Upload Media
Upload media files such as images and documents to the Daakey platform. This endpoint handles file uploads for various purposes including vehicle photos, damage documentation, announcements, and user avatars.
The upload system supports:
- Image Optimization: Uploaded images are automatically optimized for web delivery
- Collection Organization: Files are organized by collection type (vehicles, damages, avatars, etc.)
- Model Association: Files can be attached directly to specific records (vehicles, damages, etc.)
- Secure Storage: Files are stored securely with unique generated filenames
Each collection has specific file type and size restrictions to ensure optimal performance and appropriate content. See the "Supported File Types" section below for details.
Endpoint
INFO
POST /api/v1/dashboard/upload
Headers
| Header | Value | Required |
|---|---|---|
Content-Type | multipart/form-data | Yes |
Accept | application/json | Yes |
Authorization | Bearer {token} | Yes |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
file | file | Yes | File to upload |
collection | string | No | Collection name |
model_type | string | No | Model type for attachment |
model_id | integer | No | Model ID for attachment |
Example Request
bash
curl -X POST https://api.daakey.com/api/v1/dashboard/upload \
-H "Accept: application/json" \
-H "Authorization: Bearer {token}" \
-F "file=@/path/to/image.jpg" \
-F "collection=vehicles" \
-F "model_type=vehicle" \
-F "model_id=1"Response
Success (201)
json
{
"success": true,
"message": "File uploaded",
"data": {
"id": 50,
"url": "https://api.daakey.com/storage/vehicles/1/image-abc123.jpg",
"filename": "image-abc123.jpg",
"original_filename": "image.jpg",
"mime_type": "image/jpeg",
"size": 125000,
"collection": "vehicles",
"model_type": "vehicle",
"model_id": 1,
"created_at": "2024-01-15T12:00:00Z"
},
"request_id": "uuid",
"timestamp": "2024-01-01T00:00:00.000Z"
}Error (422)
json
{
"success": false,
"message": "Validation failed",
"errors": {
"file": ["The file must be an image.", "The file may not be greater than 10MB."]
},
"data": null,
"request_id": "uuid",
"timestamp": "2024-01-01T00:00:00.000Z"
}Supported File Types
| Collection | Allowed Types | Max Size |
|---|---|---|
vehicles | JPEG, PNG, WebP | 10MB |
documents | JPEG, PNG, PDF | 5MB |
avatars | JPEG, PNG | 2MB |
damages | JPEG, PNG | 5MB |
announcements | JPEG, PNG, WebP | 5MB |
Notes
- Files are stored with unique filenames
- Original filenames are preserved in metadata
- Images are automatically optimized