Pratik Borkar
Pratik Borkar

Reputation: 475

Uploading CSV files to Google Cloud Storage Using .Net Libraries

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

Answers (2)

Jorge
Jorge

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

Edwin
Edwin

Reputation: 1468

Google's .net sdk does support Big Query and Cloud Storage, but I don't have any first hand examples. Here's a link to the SDK's Supported API page. It should help if you haven't already found it. On this page there is help to using the SDK.

Upvotes: 2

Related Questions