Skip to main content

Overview

API for managing images associated with events. Supports uploading multiple images and deleting individual images.

Authentication & Permissions

All endpoints require Auth0 authentication. Permission Model:
  • Regular Users: Can upload and delete images for their own events
  • Admin Users: Can upload and delete images for all events

Upload Images to Event

POST /api/admin/events/<event_id>/images/
Upload one or more images to an event. Images are stored in Google Cloud Storage and associated with the event.

Path Parameters

event_id
number
required
Event ID

Request Body

Send as multipart/form-data with one or more files:
images
file[]
required
One or more image files to upload. Use the field name images for all files.

Response

success
boolean
Indicates if the upload was successful
message
string
Success message with count of uploaded images
images
array
Array of uploaded image objects

Example

cURL
curl -X POST "https://api.cyclemate.com/api/admin/events/123/images/" \
  -H "Authorization: Bearer YOUR_AUTH_TOKEN" \
  -F "images=@/path/to/image1.jpg" \
  -F "images=@/path/to/image2.jpg"

Success Response (201 Created)

{
  "success": true,
  "message": "Uploaded 2 image(s) successfully",
  "images": [
    {
      "id": 456,
      "image_url": "https://storage.googleapis.com/cyclemate-images/events/image1.jpg",
      "created_at": "2024-11-21T12:00:00Z"
    },
    {
      "id": 457,
      "image_url": "https://storage.googleapis.com/cyclemate-images/events/image2.jpg",
      "created_at": "2024-11-21T12:00:01Z"
    }
  ]
}

Error Responses

400 Bad Request - No files provided
{
  "error": "No files uploaded. Include files as 'images' in multipart/form-data"
}
403 Forbidden - User does not have permission
{
  "error": "You do not have permission to upload images to this event"
}
404 Not Found - Event not found
{
  "error": "Event not found"
}

Delete Image from Event

DELETE /api/admin/events/<event_id>/images/<image_id>/
Delete a specific image from an event. Removes the image record from the database and deletes the file from Google Cloud Storage.

Path Parameters

event_id
number
required
Event ID
image_id
number
required
Image ID to delete (obtained from the images array when listing events or from the upload response)

Response

success
boolean
Indicates if the deletion was successful
message
string
Confirmation message

Example

cURL
curl -X DELETE "https://api.cyclemate.com/api/admin/events/123/images/456/" \
  -H "Authorization: Bearer YOUR_AUTH_TOKEN"

Success Response (200 OK)

{
  "success": true,
  "message": "Image deleted successfully"
}

Error Responses

403 Forbidden - User does not have permission
{
  "error": "You do not have permission to delete images from this event"
}
404 Not Found - Event or image not found
{
  "error": "Image not found for this event"
}

Notes

  • Images are uploaded to Google Cloud Storage in the events folder
  • Supported image formats: JPEG, PNG, GIF, WebP (depending on GCS configuration)
  • Maximum file size depends on your server configuration (typically 10-50 MB)
  • When an event is deleted, all associated images are also deleted
  • Regular users can only manage images for events they created
  • Admin users can manage images for all events
  • The uploaded_by field is automatically set to the authenticated user making the request

Integration with Events API

These image endpoints work in conjunction with the Events API. After creating an event, you can:
  1. Upload images using POST /api/admin/events/<event_id>/images/
  2. View images in the event response (included in the images array)
  3. Delete images using DELETE /api/admin/events/<event_id>/images/<image_id>/
Images are automatically included when retrieving event details via GET /api/admin/events/<event_id>/.