简体   繁体   中英

Google Cloud and Google.Cloud.Functions.Framework

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");
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM