Home > Net >  Google Cloud and Google.Cloud.Functions.Framework
Google Cloud and Google.Cloud.Functions.Framework

Time:09-29

I'm using Google Cloud function with .net core and Google.Cloud.Functions.Framework to log user activity. I've considered to use DB to store these activities, however at first step I will try to store it in simple text file on google storage (is it proper from architectural point of view?).

My question is how can I write to google bucket using .net core and google function (my function is triggered on HTTP) and looks simple like this

    public async Task HandleAsync(HttpContext context)
    {
         //code goes here
         await context.Response.WriteAsync("Activity logged");
    }

CodePudding user response:

You would use the Google.Cloud.Storage.V1 NuGet package (documentation), just as you would from any other environment. (There's nothing special here in terms of Google Cloud Functions - authentication should work out of the box without any extra credentials.)

We have a sample function that integrates both Google Cloud Storage and the Vision API, which includes uploading a file to Google Cloud Storage.

I would recommend using dependency injection via a FunctionsStartup class to configure the StorageClient, then you should be able to just upload an object to the bucket in a straightforward way.

  • Related