包信息
| 属性 | 值 |
|---|---|
| NuGet 包 | Bitzsoft.Integrations.FileStorage.GoogleCloud |
| Provider ID | googlecloud |
| 鉴权 | ServiceAccountJwt(凭据由 IIntegrationCredentialResolver 从 Vault/KMS 解析) |
配置字段(GoogleCloudStorageOptions)
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
BucketName | string | 是 | — | 存储桶名称 |
ObjectPrefix | string? | 否 | — | 对象名前缀 |
AuthenticationMode | enum | 否 | ServiceAccountJwt | 认证模式 |
Access | enum | 否 | ReadOnly | 访问级别 |
Timeout | TimeSpan? | 否 | — | 请求超时 |
PageSize | int | 否 | 常量默认值 | 列举分页大小 |
ResumableUploadChunkSize | int | 否 | 常量默认值 | 可恢复上传分块大小 |
ApiRoot | Uri? | 否 | — | 自定义 API 网关(需同时配置 UploadApiRoot + OAuthTokenEndpoint) |
UploadApiRoot | Uri? | 否 | — | 自定义上传端点 |
OAuthTokenEndpoint | Uri? | 否 | — | 自定义 OAuth 令牌端点 |
TrustedEndpointHosts | string[] | 否 | 空 | 信任的自定义端点主机 |
AllowInsecureLoopback | bool | 否 | false | 允许不安全回环地址 |
配置示例
{ "FileStorage": { "GoogleCloud": { "BucketName": "my-bucket", "ObjectPrefix": "uploads/", "AuthenticationMode": "ServiceAccountJwt", "Access": "ReadWrite" } }}DI 注册
builder.Services.AddBitzsoftGoogleCloudStorageFileStorage(builder.Configuration.GetSection("FileStorage:GoogleCloud"));使用示例
public class GcsService(IFileStore store){ public async Task<Stream?> DownloadAsync(string fileName) { return await store.GetFileStreamAsync(fileName); }}已知限制
- 自定义端点需三件套:配置
ApiRoot时必须同时配置UploadApiRoot和OAuthTokenEndpoint,否则校验失败。全留空时使用 Google 官方端点。 - 凭据解析走
IIntegrationCredentialResolver,不通过 Options 直接配置。