Linode Object Storage with .NET and C#

Linode Object Storage is now available on Frankfurt data centre [1]. It is much more affordable and easier to manage unstructured data such as content assets (images, files etc..), sophisticated and data-intensive storage challenges around artificial intelligence and machine learning.

Since it is S3-compatible object storage, we can use AWS SDK for .NET for any operations needed.

1. Create a Project

dotnet new console 

2. Add Amazon SDK

dotnet add package AWSSDK.S3 

3. Example: List the buckets

class Program
    {
        static void Main(string[] args)
        {
            string accessKey = "**";
            string secretKey = "**";

            var config = new AmazonS3Config
            {
                RegionEndpoint = RegionEndpoint.EUCentral1, // Our bucket is on eu data center
                ServiceURL = "https://eu-central-1.linodeobjects.com" 
            };
            var amazonS3Client = new AmazonS3Client(accessKey, secretKey, config);
            ListMehmetBuckets(amazonS3Client).Wait();

        }

        static async Task ListMehmetBuckets(AmazonS3Client amazonS3Client)
        {
           var listBucketResponse = await amazonS3Client.ListBucketsAsync();
            foreach (var bucket in listBucketResponse.Buckets)
            {
                Console.Out.WriteLine("bucket '" + bucket.BucketName + "' created at " + bucket.CreationDate);
            }
            if (listBucketResponse.Buckets.Count > 0)
            {
                var bucketName = listBucketResponse.Buckets[1].BucketName;
                var listObjectsResponse = await amazonS3Client.ListObjectsAsync(bucketName);
                foreach (var obj in listObjectsResponse.S3Objects)
                {
                    Console.Out.WriteLine("key = '" + obj.Key + "' | size = " + obj.Size + " | tags = '" + obj.ETag + "' | modified = " + obj.LastModified);
                }
            }

        }
    }

You need to enable Object Storage in your Linode account before all. Check Linode docs for the details.
That’s all.

[1] Linode Storage Solutions
#linode #objectstorage #amazon-s3 #amazon-sdk-net


Comments

3 responses to “Linode Object Storage with .NET and C#”

  1. what if the linode object storage is us-southeast-1 which the regionendpoint does not exist.

    Like

    1. You are right, I couldn’t find the endpoint in RegionEndpoint class of the package. I thought S3 compatible would mean it is compatible in terms of regions as well. You can open a support ticket and ask Linode Support. Please share it here if you find a solution.

      Like

      1. If .NET SDK is not working, then non of the other amazon SDKs (node, pyhton…) would work for this case.

        Like

Leave a comment