Google Cloud StorageIntermediaUpload Service BaseUri ArgumentNullException

I am trying to upload a file to a bucket in google cloud storage.

I wrote the following code to create a StorageService and upload a file to the trash can.

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, the argument is ArgumentNullException, which says "The value cannot be empty." Parameter name: baseUri "Called when the load method is called.

Does anyone know how to fix this problem?

+3


source to share


1 answer


I also ran into this error and it happened due to having a space as the first character in my stream object. After I did it without spaces, the download worked. As Vaqar says above, this seems to be a bug by default, so not sure if this answer helps, but maybe helps others ...



0


source







All Articles