Using Amazon S3 for .NET Core 3.1 with MinIO Server
Amazon Simple Storage Service is a cloud server storage service which you can use basically to store anything.
MinIO is also a free object storage that is compatible with Amazon S3. So you can use MinIO on your development environment to test rather than sending the objects to Amazon S3.
You can follow Quickstart Guide for setting up MinIO.
MiniO has a documentation for .NET and it is straight forward. AWS also has a documentation for .NET Core. So, if you want to use it for .NET Core, you have to compose these two into one. This is what we are going to do in here:
All the in-line strings should be in appsettings.json:
So in addition to AccessKey, SecretKey, ServiceURL; I added Profile and Region.
In AWS documentation, these settings are directly being used to create a client. But if we do that, we couldn’t set ForcePathStyle=true. Which is necessary to work with MinIO. Also AWS injecting the service in Startup, right after it. But we need to edit the configurations before.
If you notice there is a AuthenticationRegion instead of RegionEndpoint. This was tricky, because first I used RegionEndpoint, but then I get lots of the following error:
The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'us-west-2'
So after that I searched a little, and found out that I should be using AuthenticationRegion if I want to inject service and use it everywhere.
Setup is done like that. For all AWS processes, I created a service called AWSService and injected right after AmazonS3. You can use this method to test if your service is working.
How to use AWS without MinIO?
If you want to use directly AWS, you can use it like in the documentation. In that case, you can set up credentials like following:
AWS only reads values like Region, Profile, ProfilesLocation. You can check options from here: ConfigurationExtensions.cs