4.1 KiB
4.1 KiB
GCS (Google Cloud Storage) Configuration Guide
Overview
All document uploads (workflow documents, work note attachments) are now configured to use Google Cloud Storage (GCS) instead of local file storage.
Configuration Steps
1. Update .env File
Add or update the following environment variables in your .env file:
# Cloud Storage (GCP)
GCP_PROJECT_ID=re-platform-workflow-dealer
GCP_BUCKET_NAME=your-bucket-name-here
GCP_KEY_FILE=./credentials/re-platform-workflow-dealer-3d5738fcc1f9.json
Important Notes:
GCP_PROJECT_ID: Should match theproject_idin your credentials JSON file (currently:re-platform-workflow-dealer)GCP_BUCKET_NAME: The name of your GCS bucket (create one in GCP Console if needed)GCP_KEY_FILE: Path to your service account credentials JSON file (relative to project root or absolute path)
2. Create GCS Bucket (if not exists)
- Go to Google Cloud Console
- Navigate to Cloud Storage > Buckets
- Click Create Bucket
- Choose a unique bucket name (e.g.,
re-workflow-documents) - Select a location for your bucket
- Set permissions:
- Make bucket publicly readable (for public URLs) OR
- Keep private and use signed URLs (more secure)
3. Grant Service Account Permissions
Your service account (re-bridge-workflow@re-platform-workflow-dealer.iam.gserviceaccount.com) needs:
- Storage Object Admin role (to upload/delete files)
- Storage Object Viewer role (to read files)
4. Verify Configuration
The system will:
- ✅ Automatically detect if GCS is configured
- ✅ Fall back to local storage if GCS is not configured
- ✅ Upload files to GCS when configured
- ✅ Store GCS URLs in the database
- ✅ Redirect downloads/previews to GCS URLs
File Storage Structure
Files are organized in GCS by request number with subfolders for documents and attachments:
reflow-documents-uat/
├── requests/
│ ├── REQ-2025-12-0001/
│ │ ├── documents/
│ │ │ ├── {timestamp}-{hash}-{filename}
│ │ │ └── ...
│ │ └── attachments/
│ │ ├── {timestamp}-{hash}-{filename}
│ │ └── ...
│ ├── REQ-2025-12-0002/
│ │ ├── documents/
│ │ └── attachments/
│ └── ...
- Documents:
requests/{requestNumber}/documents/{timestamp}-{hash}-{filename} - Work Note Attachments:
requests/{requestNumber}/attachments/{timestamp}-{hash}-{filename}
This structure makes it easy to:
- Track all files for a specific request
- Organize documents vs attachments separately
- Navigate and manage files in GCS console
How It Works
Upload Flow
- File is received via multer (memory storage)
- File buffer is uploaded to GCS
- GCS returns a public URL
- URL is stored in database (
storage_urlfield) - Local file is deleted (if it existed)
Download/Preview Flow
- System checks if
storage_urlis a GCS URL - If GCS URL: Redirects to GCS public URL
- If local path: Serves file from local storage
Troubleshooting
Files not uploading to GCS
- Check
.envconfiguration matches your credentials - Verify service account has correct permissions
- Check bucket name exists and is accessible
- Review application logs for GCS errors
Files uploading but not accessible
- Verify bucket permissions (public read or signed URLs)
- Check CORS configuration if accessing from browser
- Ensure
storage_urlis being saved correctly in database
Fallback to Local Storage
If GCS is not configured or fails, the system will:
- Log a warning
- Continue using local file storage
- Store local paths in database
Testing
After configuration:
- Upload a document via API
- Check database -
storage_urlshould contain GCS URL - Try downloading/previewing the document
- Verify file is accessible at GCS URL
Security Notes
- Public Buckets: Files are publicly accessible via URL
- Private Buckets: Consider using signed URLs for better security
- Service Account: Keep credentials file secure, never commit to git
- Bucket Policies: Configure bucket-level permissions as needed