Implementation
The main logic can be found in theservice-go-user/domain/file/provider.go file.
The local provider stores files in a local folder, while the other providers store files in their respective cloud storage services.
Configuration
This choice can be made using the GoFast CLI or by modifying thedocker-compose.yml file.
via CLI
Possible options areCloudflare R2, AWS S3, Google Cloud Storage, Azure Blob Storage and Local (folder).
via Docker Compose
Possible options arer2, s3, gcs, azblobl and local.
Files Configuration
Depending on the provider, you need to set the following environment variables in thedocker-compose.yml file:
- for
r2, setR2_ENDPOINT,R2_ACCESS_KEY, andR2_SECRET_KEY. - for
s3, setS3_REGION,S3_ACCESS_KEY, andS3_SECRET_KEY. - for
gcs, setGOOGLE_APPLICATION_CREDENTIALS. - for
azblob, setAZBLOB_ACCOUNT_NAMEandAZBLOB_ACCOUNT_KEY. - for
local, setFILE_DIR.
Getting Secrets
Cloudflare R2
- Go to Cloudflare R2 and create an account.
- Create a new bucket
- On
R2dashboard, click onManage R2 API Tokensand create a new token. - Set the
R2_ENDPOINT,R2_ACCESS_KEY, andR2_SECRET_KEYin thedocker-compose.ymlfile.
AWS S3
- Go to the AWS Console and create an account.
- Go to the S3 dashboard.
- Create a new bucket.
- Go to the IAM dashboard.
- Create a new user with
AmazonS3FullAccesspolicy. - Set the
S3_REGION,S3_ACCESS_KEY, andS3_SECRET_KEYin thedocker-compose.ymlfile.
Google Cloud Storage
- Go to the Google Cloud Console and create an account.
- Create a new project.
- Go to the Storage dashboard.
- Create a new bucket.
- Go to the IAM & Admin dashboard.
- Create a new service account with
Storage Adminrole. - Download the JSON key and set the
GOOGLE_APPLICATION_CREDENTIALSin thedocker-compose.ymlfile.
Azure Blob Storage
- Go to the Azure Portal and create an account.
- Create a new storage account.
- Go to the storage account and create a new container.
- Go to the
Access keyssection and copy theConnection string. - Set the
AZBLOB_ACCOUNT_NAMEandAZBLOB_ACCOUNT_KEYin thedocker-compose.ymlfile.