RT.MesWeb.Storage
1.2.0
dotnet add package RT.MesWeb.Storage --version 1.2.0
NuGet\Install-Package RT.MesWeb.Storage -Version 1.2.0
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="RT.MesWeb.Storage" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RT.MesWeb.Storage" Version="1.2.0" />
<PackageReference Include="RT.MesWeb.Storage" />
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 RT.MesWeb.Storage --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RT.MesWeb.Storage, 1.2.0"
#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 RT.MesWeb.Storage@1.2.0
#: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=RT.MesWeb.Storage&version=1.2.0
#tool nuget:?package=RT.MesWeb.Storage&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Storage 使用说明
安装
dotnet add package RT.MesWeb.Storage
目标框架:net8.0 / net10.0
配置要求
- 需要在
appsettings.json中添加以下配置: - 本配置节全部有默认值(
Mode默认Local),可按需覆盖;仅使用 MinIO 时需配置Minio项。 - 当
Mode为Minio时,Endpoint、AccessKey、SecretKey为必填项;缺失或为空会在启动注册阶段直接抛出InvalidOperationException,异常信息中会列出缺失的配置键。
{
"Storage": {
"Mode": "Minio", // Mode 可选值: Local;Minio
"Local": {
/* BasePath 支持多种格式:
1. 相对路径: "AppData/Files" (会解析到程序根目录下的子目录)
2. Windows绝对路径: "D:\\Storage\\MyProject"
3. Linux绝对路径: "/var/www/storage"
*/
"BasePath": "Desktop/Files",
"IsRelative": true
},
"Minio": {
"Endpoint": "127.0.0.1:9000", // Minio 服务地址
"AccessKey": "admin",
"SecretKey": "password",
"Secure": false // 是否启用 HTTPS/SSL
}
}
}
使用说明
- 需要在主工程内添加存储服务(注册为单例,
MinioClient的连接池在全进程内复用):
services.AddStorageService(configuration);
- 应用服务通过
IStorageService接口获取存储服务:
// IStorageService 的方法:
// objectFolder 对象目录:Local 模式下是根目录下的子目录,Minio 模式下是 Bucket 名
// relativePath 相对路径:Local 模式下 "/" 与 "\" 会按当前平台自动归一化
// cancellationToken 可选参数:传入后可在操作中途取消(本地存储仅在操作开始前检查)
await storage.SaveFileAsync("folder", "path/file.txt", stream, cancellationToken);
await using var readStream = await storage.GetFileAsync("folder", "path/file.txt", cancellationToken);
bool exists = await storage.FileExistsAsync("folder", "path/file.txt", cancellationToken);
await storage.DeleteFileAsync("folder", "path/file.txt", cancellationToken);
await storage.DeleteDirectoryAsync("folder", "path", cancellationToken);
行为说明
GetFileAsync返回的流必须及时释放:Local 模式返回只读FileStream;Minio 模式会先把对象落到临时文件再返回(避免大文件整体占用内存),流Dispose时临时文件自动删除。请使用using/await using。SaveFileAsync支持非可寻址流(如Request.Body):取不到长度的流会先落临时文件再上传,不会全量载入内存。FileExistsAsync只在「对象/桶不存在」时返回false;鉴权失败、地址不可达等异常会正常抛出,不会被误判为文件不存在。DeleteDirectoryAsync按前缀批量删除:Minio 模式下每批 1000 条分批删除,内存占用与目录规模无关。SaveFileAsync在 Minio 模式下会自动创建 Bucket(Bucket 名即objectFolder),创建结果在进程内缓存,不会每次上传都探测。
| 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 is compatible. 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.
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0 && < 11.0.0)
- Minio (>= 7.0.0)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0 && < 11.0.0)
- Minio (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.