Skip to content

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

HeaderValueRequired
Content-Typemultipart/form-dataYes
Acceptapplication/jsonYes
AuthorizationBearer {token}Yes

Request Body

ParameterTypeRequiredDescription
filefileYesFile to upload
collectionstringNoCollection name
model_typestringNoModel type for attachment
model_idintegerNoModel 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

CollectionAllowed TypesMax Size
vehiclesJPEG, PNG, WebP10MB
documentsJPEG, PNG, PDF5MB
avatarsJPEG, PNG2MB
damagesJPEG, PNG5MB
announcementsJPEG, PNG, WebP5MB

Notes

  • Files are stored with unique filenames
  • Original filenames are preserved in metadata
  • Images are automatically optimized

Daakey Car Sharing Platform