4.7 KiB
4.7 KiB
Edit Media API Troubleshooting Guide
Issue
Players are trying to send edited images to the server via the edit image API, but nothing is happening on the server.
Diagnosis Performed
1. API Endpoint Status ✅
- Endpoint:
POST /api/player-edit-media - Status: Exists and properly implemented
- Location:
app/blueprints/api.py(lines 711-851) - Authentication: Requires Bearer token with valid player auth code
2. Bug Found and Fixed 🐛
Found undefined variable bug in the receive_edited_media() function:
- Issue:
playlistvariable was only defined inside anifblock - Problem: When a player has no assigned playlist, the variable remained undefined
- Error: Would cause
UnboundLocalErrorwhen trying to return the response - Fix: Initialize
playlist = Nonebefore the conditional block - Commit:
8a89df3
3. Server Logs Check ✅
- No
player-edit-mediarequests found in recent logs - Conclusion: Requests are not reaching the server, indicating a client-side issue
Possible Root Causes
A. Player App Not Sending Requests
The player application might not be calling the edit media endpoint. Check:
- Is the "edit on player" feature enabled for the content?
- Does the player app have code to capture edited images?
- Are there errors in the player app logs?
B. Wrong Endpoint URL
If the player app is hardcoded with an incorrect URL, requests won't reach the server.
- Expected URL:
{server_url}/api/player-edit-media - Required Header:
Authorization: Bearer {player_auth_code}
C. Network Issues
- Firewall blocking requests
- Network connectivity issues between player and server
- SSL/HTTPS certificate validation failures
D. Request Format Issues
The endpoint expects:
Content-Type: multipart/form-data
- image_file: The edited image file (binary)
- metadata: JSON string with this structure:
{
"time_of_modification": "2026-01-17T19:50:00Z",
"original_name": "image.jpg",
"new_name": "image_v1.jpg",
"version": 1,
"user_card_data": "optional_user_code"
}
E. Authentication Issues
- Player's auth code might be invalid
- Bearer token not being sent correctly
- Auth code might have changed
Testing Steps
1. Verify Endpoint is Accessible
curl -X POST http://localhost:5000/api/player-edit-media \
-H "Authorization: Bearer <valid_player_auth_code>" \
-F "image_file=@test.jpg" \
-F "metadata={\"time_of_modification\":\"2026-01-17T20:00:00Z\",\"original_name\":\"4k1.jpg\",\"new_name\":\"4k1_v1.jpg\",\"version\":1}"
2. Check Player Logs
Look for errors in the player application logs when attempting to send edits
3. Monitor Server Logs
Enable debug logging and watch for:
docker compose logs digiserver-app -f | grep -i "edit\|player-edit"
4. Verify Player Has Valid Auth Code
curl -X POST http://localhost:5000/api/auth/verify \
-H "Authorization: Bearer <player_auth_code>" \
-H "Content-Type: application/json"
Server API Response
Success Response (200 OK)
{
"success": true,
"message": "Edited media received and processed",
"edit_id": 123,
"version": 1,
"old_filename": "image.jpg",
"new_filename": "image_v1.jpg",
"new_playlist_version": 34
}
Error Responses
- 401: Missing or invalid authorization header
- 403: Invalid authentication code
- 400: Missing required fields (image_file, metadata, etc.)
- 404: Original content file not found in system
- 500: Internal server error (check logs)
Expected Server Behavior
When an edit is successfully received:
- ✅ File is saved to
/static/uploads/edited_media/<content_id>/<filename> - ✅ Metadata JSON is saved alongside the file
- ✅ PlayerEdit record is created in database
- ✅ PlayerUser record is auto-created if user_card_data provided
- ✅ Playlist version is incremented (if player has assigned playlist)
- ✅ Playlist cache is cleared
- ✅ Action is logged in server_log table
Database Records
After successful upload, check:
-- Player edit records
SELECT * FROM player_edit WHERE player_id = ? ORDER BY created_at DESC;
-- Verify file exists
ls -la app/static/uploads/edited_media/
-- Check server logs
SELECT * FROM server_log WHERE action LIKE '%edited%' ORDER BY created_at DESC;
Next Steps
- Check if player app is configured with correct server URL
- Verify player has "edit on player" enabled for the content
- Check player app logs for any error messages
- Test endpoint connectivity using curl/Postman
- Monitor server logs while player attempts to send an edit
- Verify player's auth code is valid and unchanged