Help with Google.Cloud.Storage.v1 client libraries for .net

Hi
I am using the libraries mentioned in the topic for creating buckets in GCP which works, but I cannot find anyway to set the location of the buckets to something different then the default "us". As I and my company are working out of the EU I would really like to have the buckets placed in an datacenter in EU. Do I need to start using the Google.Apis.Storage.v1 libraries instead or is possible to set the bucket location with the Google.Cloud.Storage.v1 libraries also. All help is appreciated.

Best Regards,

Sune

 

Solved Solved
0 2 257
2 ACCEPTED SOLUTIONS

You can define the region of your bucket if you create a Bucket instance, and pass it to the CreateBucket() method (using Google.Cloud.Storage.V1).

The Bucket instance is of type Google.Apis.Storage.v1.Data.Bucket, so you'd need to have this library also in your project. You can use the snippet below to build the regional bucket (taken from this documentation page).

using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;

public class CreateRegionalBucketSample {

    public Bucket CreateRegionalBucket(
        string projectId = "your-project-id",
        string bucketName = "your-unique-bucket-name",
        string location = "us-west1",
        string storageClass = "REGIONAL") {

        var storage = StorageClient.Create();

        Bucket bucket = new Bucket {
            Location = location,
            Name = bucketName,
            StorageClass = storageClass
        };

        var newlyCreatedBucket = storage.CreateBucket(projectId, bucket);
        Console.WriteLine($"Created {bucketName}.");
        return newlyCreatedBucket;
    }
}

View solution in original post

Hi

Thanks for the explanation. I found this too a short while after posting the question. Forgot to update. Sorry.

 

Best regards,

Sune

View solution in original post

2 REPLIES 2

You can define the region of your bucket if you create a Bucket instance, and pass it to the CreateBucket() method (using Google.Cloud.Storage.V1).

The Bucket instance is of type Google.Apis.Storage.v1.Data.Bucket, so you'd need to have this library also in your project. You can use the snippet below to build the regional bucket (taken from this documentation page).

using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;

public class CreateRegionalBucketSample {

    public Bucket CreateRegionalBucket(
        string projectId = "your-project-id",
        string bucketName = "your-unique-bucket-name",
        string location = "us-west1",
        string storageClass = "REGIONAL") {

        var storage = StorageClient.Create();

        Bucket bucket = new Bucket {
            Location = location,
            Name = bucketName,
            StorageClass = storageClass
        };

        var newlyCreatedBucket = storage.CreateBucket(projectId, bucket);
        Console.WriteLine($"Created {bucketName}.");
        return newlyCreatedBucket;
    }
}

Hi

Thanks for the explanation. I found this too a short while after posting the question. Forgot to update. Sorry.

 

Best regards,

Sune