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
<PackageReference Include="Tooark.Storage.Gcp" Version="4.7.1" />
<PackageVersion Include="Tooark.Storage.Gcp" Version="4.7.1" />
<PackageReference Include="Tooark.Storage.Gcp" />
paket add Tooark.Storage.Gcp --version 4.7.1
#r "nuget: Tooark.Storage.Gcp, 4.7.1"
#:package Tooark.Storage.Gcp@4.7.1
#addin nuget:?package=Tooark.Storage.Gcp&version=4.7.1
#tool nuget:?package=Tooark.Storage.Gcp&version=4.7.1
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
- Configuration
- Credentials and URL signing
- Behavior on Google Cloud Storage
- Dependencies
- Best Practices
- Error Codes and Solutions
- Contributing
- Help & Security
- Support
- License
π§ 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
DownloadAsyncreturns aMemoryStreamwith the whole file. For large files, deliver a read signed URL. - Delete in one call β
DeleteAsyncreturnsfalsewhen 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.BucketNotFoundfor the bucket and treats the object as missing. - V4 signed URL β up to 7 days, with the verb (
GETorPUT) 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
- 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.
- Key in a vault, never in the repository β when you need a key, deliver the JSON from Secret Manager into
CredentialsJson(Storage__CredentialsJson). - Uniform bucket-level access β control access through the bucket's IAM, not object ACLs.
- CORS for direct upload β the write URL only works in the browser with a CORS configuration on the bucket that
allows
PUTfrom 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:
- π GitHub Sponsors
- β Ko-fi
Every contribution helps keep the project maintained and improving. Thank you! π
π License
This project is licensed under the BSD 3-Clause License.
| Product | Versions 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. |
-
net10.0
- Google.Cloud.Storage.V1 (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Tooark.Storage (>= 4.7.1)
-
net8.0
- Google.Cloud.Storage.V1 (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Tooark.Storage (>= 4.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.