.NET SDK (C#)

In this guide, we will show you how to use Tebi with the AWSSDK.S3 by Amazon using the dotnet utility.

Installation

Add the AWSSDK to your project via NuGet or dotnet utility.

dotnet add package AWSSDK.S3 --version 3.7.9.32

Using the SDK

As all the calls in the API are async, you may want to declare your function(s) as async. This shows an example console application which you can also find on our official GitHub page.

 1public async static Task Main()
 2{
 3    /* Fill in your data */
 4    string tebiAccessKey = "<PUT_YOUR_ACCESS_KEY>";
 5    string tebiSecretKey = "<PUT_YOUR_SECRET_KEY>";
 6    string tebiServiceURL = "https://s3.tebi.io";
 7    string tebiBucketName = "<PUT_YOUR_BUCKET_NAME>";
 8
 9    /* S3 Config Service URL */
10    Amazon.S3.AmazonS3Config cfg = new AmazonS3Config { ServiceURL = tebiServiceURL };
11
12    // This is a workaround for self signed SSL certificates!
13    // cfg.HttpClientFactory = new S3SelfSignedFactory.SSLFactory();
14
15    /* S3 Client Configuration (Key, Secret) */
16    Amazon.S3.AmazonS3Client clnt = new AmazonS3Client(awsAccessKeyId: tebiAccessKey, awsSecretAccessKey: tebiSecretKey, clientConfig: cfg);
17
18    /* List Buckets */
19    Amazon.S3.Model.ListBucketsResponse lbr = await clnt.ListBucketsAsync();
20    foreach (Amazon.S3.Model.S3Bucket b in lbr.Buckets)
21    {
22        Console.WriteLine("Bucket: {0}", (b.BucketName));
23    }
24
25    /* List Objects */
26    Console.WriteLine("Getting objects... ");
27    Amazon.S3.Model.ListObjectsResponse r = await clnt.ListObjectsAsync(tebiBucketName);
28    foreach (Amazon.S3.Model.S3Object s in r.S3Objects)
29    {
30        Console.WriteLine("Bucket {0} -> File: {1}",s.BucketName,s.Key);
31    }
32}

First, we create an instance of an S3 Config object using the service URL. The URL is usually https://s3.tebi.io, unless specified otherwise.

1string tebiServiceURL = "https://s3.tebi.io";
2...
3/* S3 Config Service URL */
4Amazon.S3.AmazonS3Config cfg = new AmazonS3Config { ServiceURL = tebiServiceURL };

In case you need to specify a URL which contains a self-signed certificate, you may need to add a workaround for the SSL Factory. This is not needed unless it is explicitly specified by your support agent.

1// This is a workaround for self signed SSL certificates!
2// cfg.HttpClientFactory = new S3SelfSignedFactory.SSLFactory();

Using this configuration object, we create an instance of the S3 client using our keys.

1string tebiAccessKey = "<PUT_YOUR_ACCESS_KEY>";
2string tebiSecretKey = "<PUT_YOUR_SECRET_KEY>";
3...
4
5/* S3 Client Configuration (Key, Secret) */
6Amazon.S3.AmazonS3Client clnt = new AmazonS3Client(awsAccessKeyId: tebiAccessKey, awsSecretAccessKey: tebiSecretKey, clientConfig: cfg);

And we are finished! Now you can use the client object to perform tasks, like listing the buckets…

1/* List Buckets */
2Amazon.S3.Model.ListBucketsResponse lbr = await clnt.ListBucketsAsync();
3foreach (Amazon.S3.Model.S3Bucket b in lbr.Buckets)
4{
5    Console.WriteLine("Bucket: {0}", (b.BucketName));
6}

Listing the files within buckets…

1string tebiBucketName = "<PUT_YOUR_BUCKET_NAME>";
2...
3/* List Objects */
4Console.WriteLine("Getting objects... ");
5Amazon.S3.Model.ListObjectsResponse r = await clnt.ListObjectsAsync(tebiBucketName);
6foreach (Amazon.S3.Model.S3Object s in r.S3Objects)
7{
8    Console.WriteLine("Bucket {0} -> File: {1}",s.BucketName,s.Key);
9}

…or any other action you would use S3 for. For more information, please refer to the official AWS SDK.