Installation
The GCS driver is included by default with Directus via the@directus/storage-driver-gcs package, which uses the official Google Cloud Storage SDK.
Configuration
Configure GCS storage using environment variables:Configuration Options
The GCS bucket name where files will be stored.
Optional path prefix for all files within the bucket.
Custom API endpoint URL for testing or alternate GCS endpoints.
Enable TUS resumable uploads. Default:
false.Chunk size for resumable uploads in bytes. Must be a power of 2 starting at 256 KiB. Minimum:
262144 (256 KiB). Default: 262144.Authentication
The GCS driver uses Google Cloud’s default authentication mechanisms:- Application Default Credentials (ADC) - Recommended for production
- Service Account Key File - Set
GOOGLE_APPLICATION_CREDENTIALSenvironment variable - Workload Identity - For Google Kubernetes Engine
- Compute Engine Service Account - Automatic on GCP compute instances
Service Account Authentication
Examples
Basic Configuration
With Root Path
With Service Account
With Resumable Uploads
Custom Endpoint (Testing)
Features
Resumable Uploads
The GCS driver supports TUS resumable uploads using GCS resumable upload protocol from/packages/storage-driver-gcs/src/index.ts:23-163:
- Creates resumable upload session with unique URI
- Supports chunk-based uploads with CRC32C validation
- Resume from any offset after interruption
- Automatic hash verification
Chunk Size Requirements
From/packages/storage-driver-gcs/src/index.ts:11,40-46:
- Minimum chunk size: 256 KiB (262144 bytes)
- Must be a power of 2 (256 KiB, 512 KiB, 1 MiB, 2 MiB, etc.)
- Invalid chunk size throws configuration error
- Default: 256 KiB
Strong Consistency
GCS provides strong read-after-write consistency:- Files are immediately readable after upload
- No eventual consistency delays
- Reliable for real-time applications
Server-Side Operations
Native GCS operations from/packages/storage-driver-gcs/src/index.ts:87-92:
- Move and copy without data transfer
- Metadata operations
- Efficient list operations with pagination
Implementation Details
The GCS driver (DriverGCS class) from /packages/storage-driver-gcs/src/index.ts:23-163:
- Uses Google Cloud Storage SDK
@google-cloud/storage - Implements resumable uploads with session management
- CRC32C checksum validation for data integrity
- Non-resumable writes for standard uploads
- Paginated listing with 500 items per page
Best Practices
Service Account Setup
Create a service account with minimal permissions:IAM Permissions
Minimum required permissions:roles/storage.objectAdmin or create custom role with minimal permissions.
Bucket Configuration
Create bucket with appropriate settings:CORS Configuration
For browser access to files:Lifecycle Management
Automate object lifecycle:Storage Classes
Choose appropriate storage class:- Standard - Frequently accessed data
- Nearline - Access < once per month
- Coldline - Access < once per quarter
- Archive - Access < once per year
Security
- Use uniform bucket-level access (recommended)
- Enable Cloud Audit Logs
- Configure VPC Service Controls for enhanced security
- Regularly rotate service account keys
- Use Workload Identity on GKE instead of key files
Performance Optimization
- Use Cloud CDN for global distribution
- Enable requester pays if appropriate
- Consider multi-regional buckets for high availability
- Use parallel composite uploads for large files (not yet in driver)
Workload Identity (GKE)
For Kubernetes deployments:Troubleshooting
Authentication Errors
- Verify
GOOGLE_APPLICATION_CREDENTIALSpoints to valid key file - Check service account has required permissions
- Ensure service account is enabled
- Verify project ID in credentials matches bucket project
Bucket Access Denied
- Check IAM permissions on the bucket
- Verify bucket exists and name is correct
- Ensure service account has
storage.objects.listpermission - Check organization policies
Invalid Chunk Size Error
If you see “Invalid chunkSize provided”:- Chunk size must be power of 2: 262144, 524288, 1048576, etc.
- Minimum is 256 KiB (262144 bytes)
- Use valid values: 256 KiB, 512 KiB, 1 MiB, 2 MiB, etc.
Resumable Upload Failures
- Check network stability
- Verify CRC32C hash validation
- Ensure upload session URI is preserved
- Check bucket quota limits
Connection Issues
- Verify network connectivity to GCS endpoints
- Check firewall rules
- Test with:
gsutil ls gs://my-bucket - Verify DNS resolution for
storage.googleapis.com