c# - 谷歌云存储 InsertMediaUpload 服务 BaseUri ArgumentNullException

标签 c# .net google-api google-oauth google-cloud-storage

我正在尝试将文件上传到谷歌云存储中的存储桶。

我编写了以下代码来创建 StorageService 并将文件上传到存储桶。

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer() {
    ClientSecrets = new ClientSecrets { ClientId = _googleSettings.ClientID, ClientSecret = _googleSettings.ClientSecret },
    DataStore = new FileDataStore(System.Web.HttpContext.Current.Server.MapPath("/App_Data")),
    Scopes = new string[] { StorageService.Scope.DevstorageReadWrite },
});

UserCredential userCredentials = new UserCredential(flow, Environment.UserName, new TokenResponse());

StorageService service = new StorageService(new BaseClientService.Initializer()
{
    HttpClientInitializer = userCredentials,
    ApplicationName = "GCS Sample"
});

Google.Apis.Storage.v1.Data.Object fileobj = new Google.Apis.Storage.v1.Data.Object() { Name = fileDetails.FileName };

ObjectsResource.InsertMediaUpload uploadService = service.Objects.Insert(fileobj, _googleSettings.BucketName, fileDetails.Stream, fileDetails.MimeContentType);

IUploadProgress progress = uploadService.Upload();

if (progress.Exception != null) //The exception always exists.
{
    throw progress.Exception;
}

但是,调用上传方法时会抛出“值不能为空。参数名称:baseUri”的 ArgumentNullException。

有谁知道如何解决这个问题?

最佳答案

我也遇到了这个错误,这是因为在我的流对象中有一个空格作为第一个字符。一旦我将其设为非空格字符,上传就成功了。正如 Vaqar 上面所说,这似乎是一个默认错误,所以不确定这个答案是否有帮助,但也许会帮助其他人......

关于c# - 谷歌云存储 InsertMediaUpload 服务 BaseUri ArgumentNullException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29820758/

相关文章:

c# - 在 .NET .config 文件中读取和写入值

c# - 我可以编写正则表达式来检查某些条件下的密码吗?

c# - Google Analytics 管理 Api 插入目标 : 403 Insufficient permission .net

xamarin - 使用 xamarin.auth 获取 google api 的刷新 token

c# - mvc索引 View 中的行计数器无法生成数字

c# - 如何获得 MIDI 事件的准确时间

c# - 如何在 C#/ASP.NET 中维护正确的 URL?

c# - 在 Windows Process Activation Services (WAS) 和 IIS 7 之间进行选择

c# - 我可以在 .Net 中加载到内存中的 DataTable 的最大大小是多少?

oauth-2.0 - 尝试从 .Net Web API 中的 Android Publisher 服务获取购买时出错