Skip to content

Google Cloud Storage

Robin Rodricks edited this page Jan 18, 2023 · 12 revisions

In order to use Google Cloud Storage reference NuGet package first.

You definitely want to use FluentStorage for working with Google Storage, as it solves quite a few issues which are hard to beat with raw SDK:

  • Listing of files and folders
  • Recursive and non-recursive listing
  • Upload and download operations are continuing to be optimised

You can initialise it in one of few ways:

Credentials stored in an environment variable

As described here

IBlobStorage storage = StorageFactory.Blobs.GoogleCloudStorageFromEnvironmentVariable(string bucketName);

Credentials stored in an external file

IBlobStorage storage = StorageFactory.Blobs.GoogleCloudStorageFromEnvironmentVariable(string bucketName, string credentialsFilePath);

Credentials passed in a string

IBlobStorage storage = StorageFactory.Blobs.GoogleCloudStorageFromEnvironmentVariable(
   string bucketName,
   string credentialsJsonString,
   bool isBase64EncodedString = false);

This method is fairly interesting, as it allows you to pass credential file content as a string. 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.

From connecting string

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.

Clone this wiki locally