Tooark.Storage.Gcp 4.7.1

dotnet add package Tooark.Storage.Gcp --version 4.7.1
                    
NuGet\Install-Package Tooark.Storage.Gcp -Version 4.7.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tooark.Storage.Gcp" Version="4.7.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tooark.Storage.Gcp" Version="4.7.1" />
                    
Directory.Packages.props
<PackageReference Include="Tooark.Storage.Gcp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tooark.Storage.Gcp --version 4.7.1
                    
#r "nuget: Tooark.Storage.Gcp, 4.7.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tooark.Storage.Gcp@4.7.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tooark.Storage.Gcp&version=4.7.1
                    
Install as a Cake Addin
#tool nuget:?package=Tooark.Storage.Gcp&version=4.7.1
                    
Install as a Cake Tool

Tooark.Storage.Gcp

Tooark.Storage provider on Google Cloud Storage. It implements IStorageService with upload, download, delete, metadata and V4 signed URLs for reading and writing.

The contract, the common options and the shared errors are in the Tooark.Storage README. This README covers what is specific to Google Cloud.

πŸ“– Docs: Tooark.Storage.Gcp on the site Β· All packages Β· API reference

🌍 Languages: πŸ‡ΊπŸ‡Έ English (this file) Β· πŸ‡§πŸ‡· PortuguΓͺs


πŸ“‘ Contents


πŸ”§ Installation

dotnet add package Tooark.Storage.Gcp

βš™οΈ Configuration

appsettings.json

On Cloud Run, GKE or Compute Engine, the bucket is enough: the credential comes from the environment's service account.

{
  "Storage": {
    "Bucket": "my-application-files",
    "SignedUrlExpirationMinutes": 15
  }
}

Program.cs

using Tooark.Storage.Gcp.Injections;

builder.Services.AddTooarkStorageGcp(builder.Configuration);

// With an adjustment in code, applied on top of the section
builder.Services.AddTooarkStorageGcp(builder.Configuration, options => options.Bucket = "another-bucket");

The registration validates the options and fails at startup when they are invalid. The credential is loaded on first use, and the client is registered as StorageClient, with one instance for the whole application.

GcpStorageOptions properties

Besides Bucket and SignedUrlExpirationMinutes, the common options:

Property Type Default Description
CredentialsJson string? β€” Content of the service account key, as JSON. Meant for a vault that delivers the JSON as text
CredentialsPath string? β€” Path of the service account key file

Provide one of them, or neither to use Application Default Credentials. Both together fail at registration.


πŸ”‘ Credentials and URL signing

Without CredentialsJson and CredentialsPath, the credential comes from Application Default Credentials (ADC): the GOOGLE_APPLICATION_CREDENTIALS variable, gcloud auth application-default login or the Cloud Run, GKE or Compute Engine service account. It is the recommended path in production: no key stays in the configuration.

With CredentialsJson or CredentialsPath, only a service account key is accepted. Loading any credential type from external JSON is what Google advises against, because the JSON can point to another token source.

URL signing depends on the credential:

Credential Signs URLs?
Service account key (CredentialsJson/Path) Yes, locally, with the private key
Cloud Run, GKE or Compute Engine service account Yes, through the IAM Credentials API (signBlob)
gcloud auth application-default login (user) No: GetSignedUrlAsync throws Storage.SigningNotSupported; the other operations work

To sign with the environment's service account, it needs the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on itself, and the IAM Service Account Credentials API must be enabled in the project.

The identity needs Storage Object Admin (roles/storage.objectAdmin) on the bucket, or the storage.objects.create, storage.objects.get and storage.objects.delete permissions.

Your own client

If the application registers its own StorageClient first, that one is used for the operations, and the options' credential applies only to URL signing.


πŸ“ Behavior on Google Cloud Storage

  • Download in memory β€” the Google client writes the object to a destination stream, so DownloadAsync returns a MemoryStream with the whole file. For large files, deliver a read signed URL.
  • Delete in one call β€” DeleteAsync returns false when the object did not exist, without a query first.
  • Missing bucket and object β€” Google answers 404 for both, and only the message tells them apart. The service throws Storage.BucketNotFound for the bucket and treats the object as missing.
  • V4 signed URL β€” up to 7 days, with the verb (GET or PUT) inside the signature: the read URL cannot be used to write.
  • Upload β€” the caller's stream is not closed, and the size comes back in Size, as reported by Google.

πŸ“‹ Dependencies

Package Version Description
Tooark.Storage 4.x Contract and common validations
Google.Cloud.Storage.V1 5.x Google Cloud Storage client
Microsoft.Extensions.Options.ConfigurationExtensions 8.x/10.x Reading the options from configuration
Microsoft.Extensions.DependencyInjection.Abstractions 8.x/10.x Container registration

🎯 Best Practices

  1. Environment service account instead of a key β€” on Cloud Run and GKE, leave the credentials empty and grant the roles to the application's service account.
  2. Key in a vault, never in the repository β€” when you need a key, deliver the JSON from Secret Manager into CredentialsJson (Storage__CredentialsJson).
  3. Uniform bucket-level access β€” control access through the bucket's IAM, not object ACLs.
  4. CORS for direct upload β€” the write URL only works in the browser with a CORS configuration on the bucket that allows PUT from the page's origin.

⚠️ Error Codes and Solutions

The configuration errors are InternalServerErrorException. Option errors come at registration (AddTooarkStorageGcp); credential errors come on first use, when it is loaded. The common operation errors are in the Tooark.Storage README.

Message When Description Solution
Options.Storage.Gcp.CredentialsAmbiguous Registration CredentialsJson and CredentialsPath together Provide only one of them
Options.Storage.Gcp.CredentialsNotFound;{path} Registration The CredentialsPath file does not exist Check the path and the mounted volume
Options.Storage.Gcp.CredentialsInvalid First use The JSON is not a valid service account key Use the JSON key generated for the service account
Options.Storage.Gcp.CredentialsUnavailable First use No key in the options and no ADC in the environment Provide the key or configure Application Default Credentials
Storage.SigningNotSupported Signed URL The credential cannot sign URLs Use a service account key or grant Service Account Token Creator

🀝 Contributing

Contributions are welcome! Start with CONTRIBUTING.md β€” it covers the development workflow, the coding and commit conventions and the pull request checklist. Bugs and feature requests go through the issue templates of the Tooark repository.

By participating you agree to the Code of Conduct.


πŸ†˜ Help & Security

  • ❓ Questions, bugs, feature ideas β€” see SUPPORT.md for the right channel
  • πŸ”’ Security vulnerabilities β€” do not open a public issue; follow SECURITY.md

πŸ’– Support

If Tooark helps your projects, consider supporting its development:

Every contribution helps keep the project maintained and improving. Thank you! πŸ™


πŸ“„ License

This project is licensed under the BSD 3-Clause License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.7.1 38 10/17/2026
4.7.0 99 9/30/2026