Google云存储InsertMediaUpload服务BaseUri ArgumentNullException

时间:2015-04-23 10:29:20

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

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

我编写了以下代码来创建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;
}

但是,调用upload方法时会抛出一个ArgumentNullException,表示“Value不能为null。参数名:baseUri”。

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

1 个答案:

答案 0 :(得分:0)

我也遇到了这个错误,这是因为我的流对象中有一个空格作为第一个字符。一旦我创建了一个非空格字符,上传工作。正如Vaqar上面所说,这似乎是一个默认错误,因此不确定这个答案是否有帮助,但可能会帮助其他人...