From f76feaaabd1e0ad11d779e54af94ed4f0b2f9199 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Tue, 18 Nov 2025 01:05:11 +0000 Subject: [PATCH] docs: Add production deployment notes for file uploads issue - Document the 404 error for uploaded images - Explain that uploads directory needs to persist in production - Provide solutions: persistent directory or cloud storage - Add debug endpoint suggestion to check upload directory --- PRODUCTION_DEPLOYMENT_NOTES.md | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 PRODUCTION_DEPLOYMENT_NOTES.md diff --git a/PRODUCTION_DEPLOYMENT_NOTES.md b/PRODUCTION_DEPLOYMENT_NOTES.md new file mode 100644 index 0000000..ca7c455 --- /dev/null +++ b/PRODUCTION_DEPLOYMENT_NOTES.md @@ -0,0 +1,63 @@ +# Production Deployment Notes + +## File Uploads Issue + +### Problem +Images are returning 404 errors in production because the uploads directory is not persisting or is in the wrong location. + +### Current Configuration +- Backend serves uploads from: `/uploads` route +- Files are stored in: `UPLOAD_DIR` environment variable (default: `./uploads`) +- File URLs in database: `/uploads/photo-{timestamp}-{random}.jpeg` + +### Solution Options + +#### Option 1: Ensure Persistent Upload Directory (Recommended) +Make sure the uploads directory on the production server persists across deployments: + +```bash +# On production server +cd /path/to/server +mkdir -p uploads +chmod 755 uploads + +# Set in .env +UPLOAD_DIR=/absolute/path/to/uploads +``` + +#### Option 2: Use Cloud Storage (Better for Production) +Instead of local file storage, use cloud storage like AWS S3, Cloudinary, or similar: + +1. Update `server/src/middleware/upload.ts` to use cloud storage +2. Update photo URLs to point to cloud storage +3. No need for local uploads directory + +### Checking Upload Directory + +Add this to your server to debug: + +```typescript +// In server/src/index.ts +app.get('/debug/uploads', (req, res) => { + const uploadDir = process.env.UPLOAD_DIR || path.join(process.cwd(), 'uploads'); + const fs = require('fs'); + + res.json({ + uploadDir, + exists: fs.existsSync(uploadDir), + files: fs.existsSync(uploadDir) ? fs.readdirSync(uploadDir) : [], + cwd: process.cwd(), + }); +}); +``` + +### Current Status +- ✅ Frontend correctly requests: `https://litter-api.psbailey.uk/uploads/photo-xxx.jpeg` +- ✅ Backend serves uploads from `/uploads` route +- ❌ Files don't exist in the uploads directory on production server + +### Action Required +1. Check if uploads directory exists on production server +2. Verify UPLOAD_DIR environment variable is set correctly +3. Ensure uploads directory has correct permissions +4. Consider implementing cloud storage for production