![]() |
VOOZH | about |
dotnet add package Galosys.Foundation.FileStorage --version 26.5.20.1
NuGet\Install-Package Galosys.Foundation.FileStorage -Version 26.5.20.1
<PackageReference Include="Galosys.Foundation.FileStorage" Version="26.5.20.1" />
<PackageVersion Include="Galosys.Foundation.FileStorage" Version="26.5.20.1" />Directory.Packages.props
<PackageReference Include="Galosys.Foundation.FileStorage" />Project file
paket add Galosys.Foundation.FileStorage --version 26.5.20.1
#r "nuget: Galosys.Foundation.FileStorage, 26.5.20.1"
#:package Galosys.Foundation.FileStorage@26.5.20.1
#addin nuget:?package=Galosys.Foundation.FileStorage&version=26.5.20.1Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.FileStorage&version=26.5.20.1Install as a Cake Tool
成熟度: 🟡 实验性 — 新增模块,接口稳定中
文件存储抽象层,基于 Plugin 策略路由模式,提供统一的文件上传/下载/预签名 URL/删除接口。通过 PluginRegistry 实现多 Provider 路由,各适配器模块按需引入。
IFileStorageProvider 定义 Upload / Download / PresignedUrl / Delete 四大操作PluginRegistry<IFileStorageProvider, FileStorageRequest> 按 Provider 名称自动路由IFileStorageProvider,无需修改业务代码dotnet add package Galosys.Foundation.FileStorage
dotnet add package Galosys.Foundation.Minio # 按需选择适配器
| 适配器 | 模块 | ProviderName | 依赖包 |
|---|---|---|---|
| Minio | Galosys.Foundation.Minio | "minio" |
minio |
| 阿里云 OSS | Galosys.Foundation.Aliyun | "aliyun-oss" |
aliyun.oss.sdk.netcore |
| 七牛 | Galosys.Foundation.Qiniu | "qiniu" |
qiniu.shared |
| 本地文件系统 | Galosys.Foundation.LocalFileSystem | "local" |
(无) |
{
"Minio": {
"Endpoint": "play.min.io", // Minio 服务地址
"AccessKey": "your-access-key",
"SecretKey": "your-secret-key",
"DefaultBucket": "my-bucket" // 默认桶名,可选
}
}
// Program.cs / Startup.cs
services.AddMinio(configuration); // 注册 Minio 适配器,同时自动注册为默认 Provider
var registry = serviceProvider.GetRequiredService<PluginRegistry<IFileStorageProvider, FileStorageRequest>>();
var provider = registry.GetPluginFor(new FileStorageRequest()); // 获取默认 Provider
await using var stream = File.OpenRead("photo.jpg");
var result = await provider.UploadAsync(stream, "images/photo.jpg", "my-bucket");
// result.FilePath → "images/photo.jpg"
// result.Url → 访问地址(如适用)
// result.Size → 文件大小
await using var stream = await provider.DownloadAsync("images/photo.jpg", "my-bucket");
var url = await provider.GetPresignedUrlAsync("images/photo.jpg", expirySeconds: 3600, bucket: "my-bucket");
await provider.DeleteAsync("images/photo.jpg", "my-bucket");
// 注册多个 Provider
services.AddMinio(configuration); // default + "minio"
services.AddLocalFileSystem(configuration); // "local"
var registry = serviceProvider.GetRequiredService<PluginRegistry<IFileStorageProvider, FileStorageRequest>>();
// 路由到指定 Provider
var minioProvider = registry.GetPluginFor(new FileStorageRequest(Provider: "minio"));
var localProvider = registry.GetPluginFor(new FileStorageRequest(Provider: "local"));
// 路由到默认 Provider(Provider 为空或 null)
var defaultProvider = registry.GetPluginFor(new FileStorageRequest());
TryAddSingleton注册策略:后注册不覆盖,第一个注册的为默认 Provider。
| 类 | 说明 |
|---|---|
IFileStorageProvider |
文件存储提供方接口,继承 Plugin<FileStorageRequest> |
FileStorageRequest |
路由请求 record(Provider / Bucket / FilePath) |
FileStorageResult |
操作结果 record(FilePath / Url / Size) |
FileStorageModule |
模块入口,实现 IModule |
FileStorageServiceCollectionExtensions |
DI 扩展方法 AddFileStorage() |
| 服务 | 实现 | 生命周期 |
|---|---|---|
PluginRegistry<IFileStorageProvider, FileStorageRequest> |
由 Core 模块统一注册 | Singleton |
IFileStorageProvider(各适配器) |
各适配器模块通过 TryAddSingleton 注册 |
Singleton |
PluginRegistry、IModule)PluginRegistry 由 Core 模块统一注册FileStorageRequest.Provider 为空或 null 时匹配默认 Provider(第一个注册的),指定名称时精确匹配| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 4 NuGet packages that depend on Galosys.Foundation.FileStorage:
| Package | Downloads |
|---|---|
|
Galosys.Foundation.Aliyun
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.Minio
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.Qiniu
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.LocalFileSystem
Galosys.Foundation快速开发库 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.20.1 | 189 | 5/20/2026 |
| 26.5.19.1 | 194 | 5/19/2026 |
| 26.5.18.1 | 187 | 5/18/2026 |
| 26.5.15.1 | 198 | 5/15/2026 |
| 26.5.12.3 | 178 | 5/12/2026 |
| 26.5.12.2 | 196 | 5/12/2026 |
| 26.4.27.1-rc1 | 166 | 4/26/2026 |
| 26.4.25.1-rc1 | 175 | 4/25/2026 |
| 26.4.22.2-rc7 | 178 | 4/22/2026 |
| 26.4.22.2-rc6 | 165 | 4/22/2026 |
| 26.4.22.2-rc4 | 174 | 4/22/2026 |
| 26.4.22.2-rc3 | 170 | 4/22/2026 |
| 26.4.19.1-rc1 | 178 | 4/19/2026 |