Skip to content

DaveCS1/SimpleS3

 
 

Repository files navigation

SimpleS3

NuGet

Description

A C# implementation of Amazon's S3 API with a focus on simplicity, security and performance. Download or upload an object with a single line of code.

Support for S3 features

  • Streaming chunked encoding support
  • Server-side encryption with customer keys
  • Support for path and virtual host style buckets
  • Support most S3 functions. See the S3 API status page. Something missing? You can help by contributing.

API features

These are the features provided by this API implementation.

Extensions

SimpleS3 is very extensible and has multiple different network drivers and addons you can use. Click on the extension below for more information.

Examples

Setup the config and client

S3Client client = new S3Client("MyKeyId", "MyAccessKey", AwsRegion.EuWest1)

Or use Microsoft's Dependency Injection

ServiceCollection services = new ServiceCollection();
services.AddSimpleS3(config => {
    config.Credentials = new SecretAccessKey("MyKeyId", "MyAccessKey");
    config.Region = AwsRegion.EuWest1;
});

ServiceProvider provider = services.BuildServiceProvider();
IS3Client client = provider.GetRequiredService<IS3Client>();

Upload an object to a bucket

await client.PutObjectStringAsync("MyBucket", "MyObject", "Hello World!");

Download an object

string content = await client.GetObjectStringAsync("MyBucket", "MyObject");

if (content != null)
    Console.WriteLine(content); //Outputs: Hello World!
else
    Console.WriteLine("Something went wrong");

Delete an object

await client.DeleteObjectAsync("MyBucket", "MyObject");

Fluent API

The fluent API makes downloading/uploading objects easier by providing a convenient way of supplying information such as cache control, content-disposition, encryption keys, etc.

//Upload string
Upload upload = client.Transfer
                 .UploadString("MyBucket", "MyObject", "Hello World!", Encoding.UTF8)
                 .WithAccessControl(ObjectCannedAcl.PublicReadWrite)
                 .WithCacheControl(CacheControlType.NoCache)
                 .WithEncryption();

PutObjectResponse resp = await upload.ExecuteAsync();
Console.WriteLine("Success? " + resp.IsSuccess);

//Download string
Download download = client.Transfer
                     .Download("MyBucket", "MyObject")
                     .WithRange(0, 5);                    

GetObjectResponse resp2 = await download.ExecuteAsync();
Console.WriteLine(await resp2.Content.AsStringAsync()); //outputs 'Hello'

See the code in SimpleS3.Examples for more examples.

About

A .NET Core implementation of Amazon's S3 API with focus on simplicity, security and performance

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%