Google云端存储InsertMediaUpload服务BaseUri ArgumentNullException [英] Google Cloud Storage InsertMediaUpload Service BaseUri ArgumentNullException
问题描述
我正在尝试将文件上传到Google云存储中的存储桶.
I am trying to upload a file to a bucket in google cloud storage.
我编写了以下代码来创建StorageService并将文件上传到存储桶中.
I wrote the following code to create the StorageService and upload the file to the bucket.
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;
}
但是,当调用上载方法时,会引发一个ArgumentNullException,其内容为值不能为空.参数名称:baseUri".
However, an ArgumentNullException that says "Value cannot be null. Parameter name: baseUri" is thrown when call the upload method.
有人知道如何解决这个问题吗?
Does anyone know how to solve this problem ?
推荐答案
我也遇到了此错误,这是由于流对象中的第一个字符是空格.一旦我将其设置为非空格字符,上传就可以正常工作.正如Vaqar所说,这似乎是默认错误,因此不确定此答案是否有帮助,但也许会帮助其他人...
I ran into this error too and it was due to having a space as the first character in my stream object. Once I made that a non-space character the upload worked. As Vaqar says above this seems to be a default error so not sure if this answer helps but maybe will help others...
这篇关于Google云端存储InsertMediaUpload服务BaseUri ArgumentNullException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!