S3FileProvider is an implementation of Microsoft.Extensions.FileProviders.Abstractions
library for AWS S3.
Library is published at Nuget.org as Evorine.FileSystem.S3FileProvider
.
Creating a S3FileProvider
instance is very simple:
var fileProvider = new S3FileProvider(amazonS3Service, bucketName);
In Configure
method:
public void Configure(IApplicationBuilder app)
{
// ...
var fileProvider = new S3FileProvider(amazonS3, "bucket-name");
var staticFilesOption = new StaticFileOptions()
{
FileProvider = fileProvider
};
app.UseStaticFiles(staticFilesOption);
// ...
}
For Amazon S3 Service instance:
var amazonS3 = new Amazon.S3.AmazonS3Client("awsAccessKeyId", "awsSecretAccessKey", Amazon.RegionEndpoint.USWest2);
Or if you have already registered Amazon S3 services in ConfigureServices
method:
var amazonS3 = app.ApplicationServices.GetService<Amazon.S3.IAmazonS3>();
That's all!
- Cancellation tokens
- File and directory watch feature
S3FileProvider.GetDirectoryContents
andS3FileProvider.GetFileInfo
throwsArgumentNullException
if null passed as path.