Dosaic.Plugins.Persistence.S3
1.1.0
See the version list below for details.
dotnet add package Dosaic.Plugins.Persistence.S3 --version 1.1.0
NuGet\Install-Package Dosaic.Plugins.Persistence.S3 -Version 1.1.0
<PackageReference Include="Dosaic.Plugins.Persistence.S3" Version="1.1.0" />
<PackageVersion Include="Dosaic.Plugins.Persistence.S3" Version="1.1.0" />
<PackageReference Include="Dosaic.Plugins.Persistence.S3" />
paket add Dosaic.Plugins.Persistence.S3 --version 1.1.0
#r "nuget: Dosaic.Plugins.Persistence.S3, 1.1.0"
#:package Dosaic.Plugins.Persistence.S3@1.1.0
#addin nuget:?package=Dosaic.Plugins.Persistence.S3&version=1.1.0
#tool nuget:?package=Dosaic.Plugins.Persistence.S3&version=1.1.0
Dosaic.Plugins.Persistence.S3
Dosaic.Plugins.Persistence.S3 is a plugin that allows other Dosaic components to interact with S3-compatible storage.
Installation
To install the nuget package follow these steps:
dotnet add package Dosaic.Plugins.Persistence.S3
or add as package reference to your .csproj
<PackageReference Include="Dosaic.Plugins.Persistence.S3" Version=""/>
Appsettings.yml
Configure your appsettings.yml with these properties:
s3:
endpoint: ""
accessKey: ""
secretKey: ""
region: ""
useSsl: true
healthCheckPath: ""
Registration and Configuration
File Storage
To use the file storage functionality, first define an enum for your buckets:
public enum MyBucket
{
[FileBucket("logos", FileType.Images)]
Logos = 0,
[FileBucket("avatars", FileType.Images)]
Avatars = 1,
[FileBucket("docs", FileType.Documents)]
Documents = 3
}
Then register the file storage for your bucket enum:
services.AddFileStorage<MyBucket>();
This registers IFileStorage<MyBucket>
which can be injected into your services.
Automatic Bucket Migration Service
To ensure buckets are created automatically when your application starts, register the migration service: The service will automatically create all buckets defined in your enum.
// Register migration service for specific buckets
services.AddBlobStorageBucketMigrationService(MyBucket.Logos);
services.AddBlobStorageBucketMigrationService(MyOtherBucket.Cars);
Basic setup without a dosaic web host (optional)
If you don't use the dosaic webhost, which automatically configures the DI container, you'll need to register the S3 plugin manually:
services.AddS3BlobStoragePlugin(new S3Configuration
{
Endpoint = "s3.example.com",
AccessKey = "your-access-key",
SecretKey = "your-secret-key",
Region = "us-west-1", // optional
UseSsl = true, // optional
HealthCheckPath = "" // optional
});
Working with Files
Example of using the file storage interface:
public class FileProvider(IFileStorage fileStorage)
{
private Task CheckPermissionAsync(FileId fileId, CancellationToken cancellationToken)
{
// check permissions or other logic
if (permission == null)
throw Exception("Could not find requested file");
}
public async Task<BlobFile> GetFileAsync(FileId id, CancellationToken cancellationToken = default)
{
await CheckPermissionAsync(id, cancellationToken);
return await fileStorage.GetFileAsync(id, cancellationToken);
}
public async Task ConsumeStreamAsync(FileId id, Func<Stream, CancellationToken, Task> streamConsumer, CancellationToken cancellationToken = default)
{
await CheckPermissionAsync(id, cancellationToken);
await fileStorage.ConsumeStreamAsync(id, streamConsumer, cancellationToken);
}
public async Task<FileId> SetAsync(BlobFile file, Stream stream, CancellationToken cancellationToken = default)
{
await CheckPermissionAsync(id, cancellationToken);
return fileStorage.SetAsync(file, stream, cancellationToken);
}
public async Task DeleteFileAsync(FileId id, CancellationToken cancellationToken = default)
{
await CheckPermissionAsync(id, cancellationToken);
await fileStorage.DeleteFileAsync(id, cancellationToken);
}
}
Example usage in a controller
[[ApiController, Route("/files"), Authorize]
public class FilesController(IFileStorage fileStorage) : ControllerBase
{
[HttpGet("{key:required}")]
public async Task<IResult> GetFileByKeyAsync([FromRoute] string key, CancellationToken cancellationToken)
{
if (!FileId.TryParse(key, out var fileId))
return Results.StatusCode(StatusCodes.Status404NotFound);
var file = await fileStorage.GetFileAsync(fileId, cancellationToken);
var etag = file.MetaData[BlobFileMetaData.ETag];
var lastModified = file.LastModified;
if (CheckIfResponseIsNotModified(etag, lastModified))
return Results.StatusCode(StatusCodes.Status304NotModified);
var fileName = file.MetaData.TryGetValue(BlobFileMetaData.Filename, out var value) ? value : fileId.Id;
Response.Headers.Append("Content-Length", file.MetaData[BlobFileMetaData.ContentLength]);
Response.Headers.Append("Cache-Control", "private, max-age=86400, immutable, must-revalidate");
return Results.Stream(sr => fileStorage.ConsumeStreamAsync(fileId, async (stream, ct) => await stream.CopyToAsync(sr, ct), cancellationToken), file.MetaData[BlobMetaData.ContentType], fileName, lastModified, new EntityTagHeaderValue(etag));
}
private bool CheckIfResponseIsNotModified(string etag, DateTimeOffset lastModified)
{
if (Request.Headers.TryGetValue("If-None-Match", out var ifNoneMatch) && ifNoneMatch == etag)
return true;
return Request.Headers.TryGetValue("If-Modified-Since", out var ifModifiedSince) &&
DateTime.TryParse(ifModifiedSince, out var modifiedSince) &&
modifiedSince >= lastModified;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- AspNetCore.HealthChecks.Uris (>= 9.0.0)
- Dosaic.Extensions.Sqids (>= 1.1.0)
- Dosaic.Hosting.Abstractions (>= 1.1.0)
- Mime-Detective (>= 24.12.2)
- Minio (>= 6.0.4)
- Sqids (>= 3.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.1.11 | 100 | 7/18/2025 |
1.1.10 | 91 | 7/18/2025 |
1.1.9 | 158 | 7/8/2025 |
1.1.8 | 148 | 7/7/2025 |
1.1.7 | 231 | 6/13/2025 |
1.1.6 | 153 | 6/5/2025 |
1.1.5 | 146 | 6/4/2025 |
1.1.4 | 139 | 6/4/2025 |
1.1.3 | 141 | 5/23/2025 |
1.1.2 | 158 | 5/8/2025 |
1.1.1 | 162 | 5/6/2025 |
1.1.0 | 118 | 5/2/2025 |
1.0.37 | 181 | 4/7/2025 |
1.0.36 | 487 | 3/25/2025 |
1.0.35 | 239 | 3/4/2025 |
1.0.34 | 218 | 3/4/2025 |
1.0.32 | 159 | 3/3/2025 |
1.0.30 | 135 | 1/30/2025 |
1.0.27 | 108 | 1/29/2025 |
1.0.26 | 103 | 1/29/2025 |
1.0.25 | 102 | 1/29/2025 |
1.0.18 | 120 | 1/23/2025 |
1.0.17 | 103 | 1/23/2025 |