BugFree.FileStorage
1.0.2026.107-beta1426
This is a prerelease version of BugFree.FileStorage.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package BugFree.FileStorage --version 1.0.2026.107-beta1426
NuGet\Install-Package BugFree.FileStorage -Version 1.0.2026.107-beta1426
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="BugFree.FileStorage" Version="1.0.2026.107-beta1426" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BugFree.FileStorage" Version="1.0.2026.107-beta1426" />
<PackageReference Include="BugFree.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 BugFree.FileStorage --version 1.0.2026.107-beta1426
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BugFree.FileStorage, 1.0.2026.107-beta1426"
#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 BugFree.FileStorage@1.0.2026.107-beta1426
#: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=BugFree.FileStorage&version=1.0.2026.107-beta1426&prerelease
#tool nuget:?package=BugFree.FileStorage&version=1.0.2026.107-beta1426&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FileStorage 模块说明
组成
BugFree.FileStorage:封装文件存储抽象(IFileStorage/IBucketStorage)、动态提供者选择(FileStorageService),内置阿里云 OSS、腾讯云 COS、本地文件系统实现。BugFree.Controllers.FileStorage:对外 REST 控制器,区域默认Oss,包含配置读取与文件操作接口,支持事件回调(FileStorageEventHandler)。
支持能力
- Bucket(可选):存在性检查、创建、删除(接口
IBucketStorage)。 - Object(核心):上传(流/路径)、下载(流/路径)、删除、判断存在、生成访问 URL(签名)、复制。
- 元信息:
FileMetadata模型可按需扩展(暂未暴露在控制器)。
配置
配置模型 FileStorageSetting(Config<FileStorageSetting>,支持加密存储):
{
"Provider": "AliCloud | TencentCloud | Local | None",
"AliCloud": {
"Region": "cn-hangzhou",
"Endpoint": "https://oss-cn-hangzhou.aliyuncs.com",
"BucketName": "your-bucket",
"AccessKeyId": "<YOUR_KEY>",
"AccessKeySecret": "<YOUR_SECRET>"
},
"TencentCloud": {
"AppId": "<APPID>",
"Region": "ap-guangzhou",
"SecretId": "<SECRET_ID>",
"SecretKey": "<SECRET_KEY>",
"BucketName": "your-bucket-123456",
"Url": "https://your-bucket-123456.cos.ap-guangzhou.myqcloud.com"
},
"Local": {
"RootPath": "./files",
"AccessUrl": "http://localhost:5000/",
"ParamEncryptKey": "<RANDOM_KEY>"
}
}
依赖注入
- 服务注册:
services.AddFileStorageService(); - 控制器事件注册:
services.AddFileStorage(new FileStorageEventHandler { /* 订阅事件 */ }); FileStorageService根据FileStorageSetting.Current.Provider惰性创建具体实现。
事件回调(可选)
通过 FileStorageEventHandler 订阅以下事件,控制器在操作成功后调用:
Uploaded(bucket, key)Presigned(bucket, key, url)Deleted(bucket, key)ExistsChecked(bucket, key, exists)Copied(sourceBucket, sourceKey, destBucket, destKey)
控制器接口(默认路由示例)
POST /Oss/v1/FileStorage/Upload?bucket=&key=:上传文件(表单file)。GET /Oss/v1/FileStorage/Presign?bucket=&key=&minutes=5:生成临时访问地址。DELETE /Oss/v1/FileStorage/Delete?bucket=&key=:删除对象。GET /Oss/v1/FileStorage/Exists?bucket=&key=:判断对象是否存在。POST /Oss/v1/FileStorage/Copy?sourceBucket=&sourceKey=&destBucket=&destKey=:复制对象。GET /Oss/v1/Setting/Get:读取当前FileStorageSetting(继承自ConfigControllerBase标准路由)。
本地存储说明
RootPath为空时回退当前目录,按bucket/key组织文件。AccessUrl必填用于生成可访问 URL;ParamEncryptKey用于对访问参数加密(对称加密算法随机择取)。
使用示例
// 注册
services.AddFileStorageService();
services.AddFileStorage(new FileStorageEventHandler
{
Uploaded = (bucket, key) => new ValueTask(Task.CompletedTask)
});
// 服务侧上传
await _fileStorageService.Upload("demo", "path/demo.txt", stream);
var url = await _fileStorageService.GeneratePresignedUrl("demo", "path/demo.txt", TimeSpan.FromMinutes(10));
注意事项
- SDK 调用结果异常会抛出,调用方需处理(网络/权限/配置)。
- 若当前 Provider 不支持 Bucket 操作会抛出
NotSupportedException。 - 不要提交真实密钥,示例中请替换占位符。
| 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
- AlibabaCloud.OSS.V2 (>= 0.1.2)
- BugFree.Configuration (>= 1.0.2026.106-beta1135)
- Microsoft.Extensions.Options (>= 10.0.1)
- Tencent.QCloud.Cos.Sdk (>= 5.4.49)
-
net8.0
- AlibabaCloud.OSS.V2 (>= 0.1.2)
- BugFree.Configuration (>= 1.0.2026.106-beta1135)
- Microsoft.Extensions.Options (>= 10.0.1)
- Tencent.QCloud.Cos.Sdk (>= 5.4.49)
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.2026.325-beta1128 | 56 | 3/25/2026 |
| 1.1.2026.325-beta1042 | 43 | 3/25/2026 |
| 1.1.2026.325-beta1036 | 41 | 3/25/2026 |
| 1.1.2026.325-beta1013 | 47 | 3/25/2026 |
| 1.1.2026.303-beta1510 | 55 | 3/3/2026 |
| 1.1.2026.127-beta1557 | 58 | 3/3/2026 |
| 1.1.2026.115-beta1541 | 71 | 1/15/2026 |
| 1.0.2026.107-beta1426 | 66 | 1/7/2026 |
| 1.0.2026.106-beta1144 | 64 | 1/6/2026 |
| 1.0.2025.1224-beta1658 | 146 | 12/24/2025 |
| 1.0.2025.1224-beta1527 | 138 | 12/24/2025 |
| 1.0.2025.1224-beta1412 | 144 | 12/24/2025 |