Trying to upload a file to Google Cloud Storage using Google APIs Client Library for .Net. Here is my code. It runs fine without any errors but doesn't do the job either. Please advice what I'm missing here, or is it the right way to approach this problem. Apreciate it!
try
{
Google.Apis.Services.BaseClientService.Initializer init = new Google.Apis.Services.BaseClientService.Initializer();
init.ApiKey = "server-apps-API-KEY-HERE";
init.ApplicationName = "Project Default Service Account";
Google.Apis.Storage.v1.StorageService ss = new Google.Apis.Storage.v1.StorageService(init);
Google.Apis.Storage.v1.Data.Object fileobj = new Google.Apis.Storage.v1.Data.Object();
fileobj.ContentType = "image/jpeg";
///READ FILE
string file = @"C:\Photos\TEST.jpg";
System.IO.Stream j = new System.IO.FileStream(file,
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
//New File Name
fileobj.Name = "TEST.jpg";
Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload insmedia;
insmedia = new Google.Apis.Storage.v1.ObjectsResource.InsertMediaUpload(ss, fileobj, "test-common", j, "image/jpeg");
insmedia.Upload();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}