A nuget package which allows you to integrate S3 storage into your Web Application. Also, the library allows you to use localstack for debugging.
dotnet add package AspNetCore.Aws.S3.Simple
For simple demo, you need Docker installed in your PC. If you have it, then follow the instruction:
- Pull the repo
- run
win-run.ps1orunix-run.ps1script - Go to https://localhost:5001/swagger/index.html. There are two endpoints:
/files/uploadand/files/download.
- Install the nuget package
AspNetCore.Aws.S3.Simple; - Create inheritors of
IFileStorageBase.csandAmazonS3StorageBase;
using S3.Integration.AmazonServices;
using S3.Integration.Contracts;
using S3.Integration.Settings;
public interface IAvatarsStorage : IFileStorageBase
{
}
public class AvatarsS3Storage : AmazonS3StorageBase, IAvatarsStorage
{
public AvatarsS3Storage(
S3StorageSettings configuration,
IS3FileValidator fileValidator)
: base(configuration, fileValidator, "user-avatars")
{
}
}- Add settings in the Startul.cs or Program.cs file:
var builder = WebApplication.CreateBuilder(args);
// ...
builder.Services
.AddS3Settings()
.AddS3Storage<IAvatarsStorage, AvatarsS3Storage>();- Add healthcheck settings (if necessary):
builder.Services
.AddHealthChecks()
.AddS3HealthChecks(builder.Configuration);- Use the storage service
- Add API for reading all files in the bucket
- Storing private and public files
CHeck out this sample Web.Api project and see how to use the nuget
- https://helibertoarias.com/blog/aws/localstack-using-s3-with-net-core/
- https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/tree/master/src/HealthChecks.Aws.S3
- https://purple.telstra.com/blog/local-amazon-s3
- https://github.com/localstack/localstack
- https://www.stevejgordon.co.uk/running-aws-s3-simple-storage-service-using-docker-for-net-core-developers
- https://github.com/dayanrr91/aws-net-core-examples