This endpoint requires authentication. Users can only delete their own media files.
Overview
Permanently delete a media file from both Supabase Storage and the database. This action cannot be undone.Path Parameters
The database ID of the media item to delete. You can get this from the
GET /api/user/media endpoint.Deletion Process
What Gets Deleted
- File from Supabase Storage: The actual media file is removed from the
user-mediabucket - Database Record: The media record is removed from the
user_mediatable - Community Copies (if shared to community):
- Community media record in
community_mediatable - File from
generalbucket - Associated tag assignments
- Community media record in
Orphaned File Handling
If the database record exists but the storage file is already deleted:- The database record is still removed
- A warning is logged but the operation succeeds
- The API returns a success response
Authorization
- Users can only delete their own media
- The endpoint verifies that
media.userIdmatches the authenticated user’s ID - Returns
404 Not Foundif media doesn’t exist or belongs to another user
Response
Success Response
Confirmation message: “Media deleted successfully”
Error Responses
400 Bad Request
Invalid media ID:404 Not Found
Media not found or unauthorized:- The media ID doesn’t exist in the database
- The media belongs to a different user
500 Internal Server Error
Database deletion failed:Activity Tracking
Successful deletions are logged with:- Action:
media_deleted - Feature:
media_gallery - Details: Media ID and metadata
Example Usage
cURL
JavaScript (Fetch API)
React Example with Confirmation
Bulk Delete Example
Alternative Endpoint
DELETE /api/user/media/:fileName (Legacy)
This legacy endpoint accepts a file path instead of database ID:- Accepts file path relative to
users/{userId}/ - Looks up database record by
filePath - Same deletion behavior otherwise
DELETE /api/user/media/:id) for better reliability and consistency.
Notes
- Deletion is permanent and cannot be undone
- Both storage and database records are deleted
- If the media was shared to community, the community copy is also removed
- The endpoint gracefully handles cases where the storage file is already deleted
- Consider implementing soft deletes if you need recovery capability
- For bulk deletions, consider implementing a dedicated bulk delete endpoint to reduce API calls