I am trying to upload a file to a bucket in google cloud storage.
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;
}
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 ?