-
-
Notifications
You must be signed in to change notification settings - Fork 69
Google Cloud Storage
In order to use Google Cloud Storage reference package first.
You definitely want to use FluentStorage for working with Google Storage, as it solves quite a few issues which are hard to manage with the raw SDK:
- Listing of files and folders
- Recursive and non-recursive listing
- Upload and download operations are continuing to be optimised
You can configure Service Account IAM permissions for accessing GCS buckets, and then simply omit the cred in the connection string, and then FluentStorage will fallback to connecting using the Workload Identity setup.
You can then use Application Default Credentials (ADC), which is the recommended authentication approach for workloads running on Google Cloud and even for local development via gcloud auth application-default login.
If you have credentials stored in an environment variable. (As described here)
IBlobStorage storage = StorageFactory.Blobs.GoogleCloudStorageFromEnvironmentVariable(bucketName);If you have credentials stored in an external JSON file.
IBlobStorage storage = StorageFactory.Blobs.GoogleCloudStorageFromJsonFile(bucketName, filePath);If you need the credentials passed as a JSON string.
IBlobStorage storage = StorageFactory.Blobs.GoogleCloudStorageFromJson(
bucketName, credentialsJsonString, isBase64EncodedString = false);The last parameter says whether the string is base64 encoded or not, which is handy if credentials are stored in some sort of config file.
First, don't forget to initialise the module:
StorageFactory.Modules.UseGoogleCloudStorage();Then, use the string:
IBlobStorage storage = StorageFactory.Blobs.FromConnectionString("google.storage://bucket=...;cred=...");Where cred is a BASE64 encoded credential string.