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.
- 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.
These are the features provided by this API implementation.
- Supports a fluent API to make it easy to download/upload an object
- Uses HttpClientFactory for optimal performance and flexibility
- Dependency injection friendly. By default uses Microsoft.Extensions.DependencyInjection
- Supports configuration binding via Microsoft.Extensions.Configuration
- Extensive unit tests ensure correctness and stability
- Support for uploading/downloading multiparts in parallel
- Support for third-party servers like Minio and Wasabi
- ProfileManager to securely manage credentials
SimpleS3 is very extensible and has multiple different network drivers and addons you can use. Click on the extension below for more information.
- SimpleS3.Extensions.HttpClient
- SimpleS3.Extensions.HttpClientFactory
- SimpleS3.Extensions.ProfileManager
S3Client client = new S3Client("MyKeyId", "MyAccessKey", AwsRegion.EuWest1)
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>();
await client.PutObjectStringAsync("MyBucket", "MyObject", "Hello World!");
string content = await client.GetObjectStringAsync("MyBucket", "MyObject");
if (content != null)
Console.WriteLine(content); //Outputs: Hello World!
else
Console.WriteLine("Something went wrong");
await client.DeleteObjectAsync("MyBucket", "MyObject");
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.