Reputation: 475
I need help on writing a code for uploading locally stored CSV files to Google cloud storage and then storing data from storage to the respective Big Query tables, using .Net client libraries.
I searched for hours, but didn't get relevant solution.
Thanks.
Upvotes: 3
Views: 3360
Reputation: 51
// IMPORTANT: YOU ALSO NEED TO ACTIVATE Google Cloud Storage JSON API ON YOUR GOOGLE APIS CONSOLE. // Google Cloud Storage IS NOT ENOUGH EVEN IF YOU ARE NOT USING JSON ON YOUR .NET CODE
Google.Apis.Storage.v1beta1.Data.Object fileobj = new Google.Apis.Storage.v1beta1.Data.Object();
fileobj.Media = new Google.Apis.Storage.v1beta1.Data.Object.MediaData();
fileobj.Media.ContentType = "application/octet-stream";
///READ FILE
string file = @"C:\2noviembre.csv";
System.IO.Stream j = new System.IO.FileStream(file,
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
//New File Name
fileobj.Name = "testloco.csv";
Google.Apis.Storage.v1beta1.ObjectsResource.InsertMediaUpload insmedia;
insmedia = new Google.Apis.Storage.v1beta1.ObjectsResource.InsertMediaUpload(storservice, fileobj, "YOURBUCKETNAME", j, "application/octet-stream");
insmedia.Upload();
MessageBox.Show("Enviado");
Upvotes: 5