AWS SDK for .NET
Website at https://docs.aws.amazon.com/sdk-for-net.
Installation:
$ dotnet new console -o myApp
$ cd myApp
$ dotnet add package AWSSDK.S3 --version 3.3.110.19
Edit `Program.cs` to have the following contents (substituting `mybucket`, `<your access key>`. `<your secret>` with your information):
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.IO;
using System.Threading.Tasks;
namespace Amazon.DocSamples.S3
{
class ListObjectsTest
{
private const string bucketName = "mybucket";
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USEast1;
private static IAmazonS3 client;
public static void Main()
{
string accessKey = "<your access key>";
string secretKey = "<your secret>";
var config = new AmazonS3Config {
ServiceURL = "https://polycloud.crowdapis.com",
};
client = new AmazonS3Client(
accessKey,
secretKey,
config
);
ListingObjectsAsync().Wait();
}
static async Task ListingObjectsAsync()
{
try
{
ListObjectsV2Request request = new ListObjectsV2Request
{
BucketName = bucketName
};
ListObjectsV2Response response;
do
{
response = await client.ListObjectsV2Async(request);
foreach (S3Object entry in response.S3Objects)
{
Console.WriteLine(entry.Key);
}
request.ContinuationToken = response.NextContinuationToken;
} while (response.IsTruncated);
}
catch (AmazonS3Exception amazonS3Exception)
{
Console.WriteLine("S3 error occurred. Exception: " + amazonS3Exception.ToString());
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
Console.ReadKey();
}
}
}
}
Run the example*:
$ dotnet run
*You may have to add the following to `./bin/Debug/netcoreapp3.1/myApp.runtimeconfig.json`:
"configProperties": {
"System.Globalization.Invariant": true
}