{ "success": true, "message": "Folder created successfully", "data": { "folderPath": "vacation/2024/spring", "folderName": "spring", "parentPath": "vacation/2024", "created": "2023-08-15T10:30:00Z", "exists": false } }
Create new folders in the photo collection
curl -X POST http://localhost:3000/api/folders \ -H "Content-Type: application/json" \ -H "Cookie: session-cookie" \ -d '{"path": "new-album", "name": "new-album"}'
curl -X POST http://localhost:3000/api/folders \ -H "Content-Type: application/json" \ -H "Cookie: session-cookie" \ -d '{"path": "vacation/2024/spring", "name": "spring"}'
{ "success": true, "message": "Folder already exists", "data": { "folderPath": "vacation/2023", "folderName": "2023", "parentPath": "vacation", "created": "2023-01-15T08:20:00Z", "exists": true } }
{ "success": false, "error": "Invalid folder name contains prohibited characters", "code": "INVALID_FOLDER_NAME", "details": { "prohibitedChars": ["<", ">", ":", "\"", "|", "?", "*", "\\"] } }
< > : " | ? * \
async function createFolder(folderPath, folderName) { try { const response = await fetch('/api/folders', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', // Include session cookie body: JSON.stringify({ path: folderPath, name: folderName }) }); const result = await response.json(); if (result.success) { if (result.data.exists) { console.log('Folder already exists:', result.data.folderPath); } else { console.log('Folder created:', result.data.folderPath); } return result.data; } else { throw new Error(result.error); } } catch (error) { console.error('Folder creation failed:', error); throw error; } } // Usage examples createFolder('events/2024', '2024') .then(folder => { console.log('Ready to upload to:', folder.folderPath); }); createFolder('backup/old-photos', 'old-photos') .then(folder => { console.log('Backup folder ready:', folder.folderPath); });
// This will create all necessary parent folders: // - events/ // - events/2024/ // - events/2024/wedding/ // - events/2024/wedding/ceremony/ createFolder('events/2024/wedding/ceremony', 'ceremony');