{ "success": true, "message": "3 images deleted successfully", "data": { "deletedImages": [ { "path": "vacation/2023/photo1.jpg", "status": "deleted", "size": 2048576 }, { "path": "vacation/2023/photo2.png", "status": "deleted", "size": 1536000 }, { "path": "old-photos/sunset.jpg", "status": "deleted", "size": 3072000 } ], "totalDeleted": 3, "totalSize": 6656576 } }
Delete images from the photo frame collection
curl -X DELETE http://localhost:3000/api/images \ -H "Content-Type: application/json" \ -H "Cookie: session-cookie" \ -d '{"images": ["vacation/2023/photo1.jpg"]}'
curl -X DELETE http://localhost:3000/api/images \ -H "Content-Type: application/json" \ -H "Cookie: session-cookie" \ -d '{"images": ["vacation/2023/photo1.jpg", "vacation/2023/photo2.png", "old-photos/sunset.jpg"]}'
{ "success": true, "message": "2 of 3 images deleted successfully", "data": { "deletedImages": [ { "path": "vacation/2023/photo1.jpg", "status": "deleted", "size": 2048576 }, { "path": "vacation/2023/photo2.png", "status": "deleted", "size": 1536000 }, { "path": "missing/photo.jpg", "status": "not_found", "error": "File does not exist" } ], "totalDeleted": 2, "totalSize": 3584576 } }
{ "success": false, "error": "No images specified for deletion", "code": "MISSING_IMAGES_PARAMETER" }
async function deleteImages(imagePaths) { try { const response = await fetch('/api/images', { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, credentials: 'include', // Include session cookie body: JSON.stringify({ images: imagePaths }) }); const result = await response.json(); if (result.success) { console.log(`Deleted ${result.data.totalDeleted} images`); // Check for any failures const failed = result.data.deletedImages.filter(img => img.status !== 'deleted'); if (failed.length > 0) { console.warn('Some images could not be deleted:', failed); } return result.data.deletedImages; } else { throw new Error(result.error); } } catch (error) { console.error('Delete failed:', error); throw error; } } // Usage example const imagesToDelete = [ 'vacation/2023/blurry-photo.jpg', 'old-photos/duplicate.png' ]; deleteImages(imagesToDelete) .then(results => { console.log('Deletion complete:', results); }) .catch(error => { console.error('Deletion failed:', error); });