gcp authenticating using client sdk - service account approach.

Create a service account in IAM and Admin. Once you have done that, go to your newly created service account and then click on Create Key Pair. Then it will automatically download the private key json

Create your gcp storage bucket. The under permission tab, grant your service account access perhaps with a role "storage object creator".

Let's switch to your laptop and fireup a console c# project. Add google bucket sdk libraries into the by running:

dotnet add package Google.Cloud.Storage.V1 --version 4.10.0

Then configure the environment variables 

GOOGLE_APPLICATION_CREDENTIALS=path-to-your-json.key 

for example "C:\\work\\gcp-cred\\gcp-myprivate-project-14197e38ef68.json"

Then use the following code to test out your configurations


using Google.Cloud.Storage.V1;
// upload
var objectName = "readme.md";
var storage = StorageClient.Create();
using var fileStream = File.OpenRead("c:\\work\\foctest\\README.md");
storage.UploadObject("mytestdevbucketgcp", objectName, null, fileStream);
Console.WriteLine($"Uploaded {objectName}.");











Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm