【发布时间】:2022-10-23 21:11:14
【问题描述】:
我正在尝试设置local emulator of GCP storage(非官方)与.NET client library 一起使用。但是我不确定如何覆盖似乎被硬编码为storage.googleapis.com 的基本存储 URL。
我在模拟器描述中看到STORAGE_EMULATOR_HOST 参数,但它似乎不适用于.NET 客户端库:|
我检查了一些库代码,并在内部 StorageService 类中找到了这个代码:
有什么方法可以覆盖 .NET 6 / Core 中的 BaseUri?
我的部分代码/配置供参考:
// Configuration
private static void AddGcpServices(this IServiceCollection services, IConfiguration configuration)
{
// Dev only for now
var storageClient = StorageClient.CreateUnauthenticated();
services.AddSingleton(storageClient);
services.AddSingleton<ICloudStorage, CloudStorage>();
}
// ...
// Storage
public class CloudStorage : ICloudStorage
{
private readonly StorageClient _client;
public CloudStorage(StorageClient client)
{
_client = client;
}
public async Task<Uri> SaveFile(string containerName, string fullSavePath, Stream file, CancellationToken cancellationToken = default)
{
var result = await _client.UploadObjectAsync(containerName, fullSavePath, null, source: file,
cancellationToken: cancellationToken);
return result.MediaLink.ToUri();
}
}
【问题讨论】:
标签: c# .net google-cloud-platform google-cloud-storage emulation