Galosys.Foundation.FileStorage
26.5.20.1
dotnet add package Galosys.Foundation.FileStorage --version 26.5.20.1
NuGet\Install-Package Galosys.Foundation.FileStorage -Version 26.5.20.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.FileStorage" Version="26.5.20.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.FileStorage" Version="26.5.20.1" />
<PackageReference Include="Galosys.Foundation.FileStorage" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.FileStorage --version 26.5.20.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.FileStorage, 26.5.20.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.FileStorage@26.5.20.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.FileStorage&version=26.5.20.1
#tool nuget:?package=Galosys.Foundation.FileStorage&version=26.5.20.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Galosys.Foundation.FileStorage
成熟度: 🟡 实验性 — 新增模块,接口稳定中
简介
文件存储抽象层,基于 Plugin 策略路由模式,提供统一的文件上传/下载/预签名 URL/删除接口。通过 PluginRegistry 实现多 Provider 路由,各适配器模块按需引入。
特性
- 统一接口 —
IFileStorageProvider定义 Upload / Download / PresignedUrl / Delete 四大操作 - 策略路由 — 基于
PluginRegistry<IFileStorageProvider, FileStorageRequest>按 Provider 名称自动路由 - 多提供方共存 — 支持 Minio、阿里云 OSS、七牛、本地文件系统等多种存储后端
- 零侵入扩展 — 各适配器模块独立注册
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 示例)
{
"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
使用 PluginRegistry 获取 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");
预签名 URL
var url = await provider.GetPresignedUrlAsync("images/photo.jpg", expirySeconds: 3600, bucket: "my-bucket");
删除文件
await provider.DeleteAsync("images/photo.jpg", "my-bucket");
多 Provider 路由
// 注册多个 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() |
DI 注册详情
| 服务 | 实现 | 生命周期 |
|---|---|---|
PluginRegistry<IFileStorageProvider, FileStorageRequest> |
由 Core 模块统一注册 | Singleton |
IFileStorageProvider(各适配器) |
各适配器模块通过 TryAddSingleton 注册 |
Singleton |
依赖
- Galosys.Foundation.Core(提供
PluginRegistry、IModule) - Microsoft.Extensions.DependencyInjection
注意事项
- FileStorage 模块本身不需要额外配置,
PluginRegistry由 Core 模块统一注册 - 各适配器模块独立引用,业务项目只需引用所需适配器即可
FileStorageRequest.Provider为空或 null 时匹配默认 Provider(第一个注册的),指定名称时精确匹配
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Galosys.Foundation.Core (>= 26.5.20.1)
NuGet packages (4)
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快速开发库 |
GitHub repositories
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 |