Files not displaying after upload due to missing EVIDENCE_DIR and EVIDENCE_URL_SECRET environment variables. Uploads fail silently when env vars unset, files never inserted into database. Add bug fix documentation with root cause analysis and VPS deployment instructions. Update .env.local.example to emphasize these vars are required for file uploads to work. See docs/BUG_FIX_evidence_display.md for details.
1.9 KiB
1.9 KiB
Bug Fix: Files Not Displaying After Upload
Issue
After users report incidents and upload images/videos/documents, the files don't display in the incident detail page under the evidence section.
Root Cause
The uploadEvidenceFile() function in lib/storage/evidence.ts requires two environment variables:
EVIDENCE_DIR— filesystem path to store evidence filesEVIDENCE_URL_SECRET— HMAC secret for signing secure file URLs
When these variables are missing:
- File upload API receives files from client
- Calls
uploadEvidenceFile()at/api/incidents/route.ts:154 - Function throws error (e.g., "EVIDENCE_DIR env var not set")
- Error caught silently at line 164:
catch (err) { console.error(...) } - Evidence not inserted into database
- Display shows empty file list
Related Changes
- Commit
e5f74c3(2026-07-23): Switched from Supabase storage to local filesystem with HMAC-signed URLs - This change requires new env vars that weren't documented in deployment checklist
Fix
Set environment variables before starting the app:
# Generate secret
EVIDENCE_URL_SECRET=$(openssl rand -hex 32)
# Export or add to .env file
export EVIDENCE_DIR=/var/lib/ims-evidence
export EVIDENCE_URL_SECRET=$EVIDENCE_URL_SECRET
# Create directory with proper permissions
mkdir -p $EVIDENCE_DIR
chmod 755 $EVIDENCE_DIR
For VPS systemd service, add to /etc/systemd/system/ims.service:
Environment="EVIDENCE_DIR=/var/lib/ims-evidence"
Environment="EVIDENCE_URL_SECRET=<generated-secret>"
Then reload and restart:
sudo systemctl daemon-reload
sudo systemctl restart ims
Testing
- Report incident with file upload
- Check
/var/lib/ims-evidencedirectory—files should appear as<user-id>/<incident-id>/report/<timestamp>-<random>.<ext> - Verify via HSE incident detail page—files should display in gallery
- Check database:
SELECT COUNT(*) FROM evidence_files WHERE deleted = false