OnceMi.AspNetCore.OSS
1.2.0
dotnet add package OnceMi.AspNetCore.OSS --version 1.2.0
NuGet\Install-Package OnceMi.AspNetCore.OSS -Version 1.2.0
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" />
paket add OnceMi.AspNetCore.OSS --version 1.2.0
#r "nuget: OnceMi.AspNetCore.OSS, 1.2.0"
// Install OnceMi.AspNetCore.OSS as a Cake Addin #addin nuget:?package=OnceMi.AspNetCore.OSS&version=1.2.0 // Install OnceMi.AspNetCore.OSS as a Cake Tool #tool nuget:?package=OnceMi.AspNetCore.OSS&version=1.2.0
OnceMi.AspNetCore.OSS
Asp.Net Core对象储存扩展包,支持Minio自建对象储存、阿里云OSS、腾讯云COS、七牛云Kodo、华为云OBS。支持OSS常规操作,比如储存桶创建,删除、对象上传、下载、生成签名URL等。目前支持.NET Core3.1/.NET 5/.NET 6,推荐升级至.NET 6.
各厂家相关SDK文档
已知问题
- Minio通过Nginx发反向代理后直接通过域名(不加端口)调用存在问题,应该是Minio本身问题,有兴趣的可以自行测试研究,具体信息我已经发布在Issue中。
- 腾讯云
PutObjectAsync
流式上传接口,有非常低的概率会抛“储存桶不存在的异常”,应该是腾讯云自身的原因,具体原因未知。
如何使用
1、安装OnceMi.AspNetCore.OSS
依赖。
Cmd install:
dotnet add package OnceMi.AspNetCore.OSS
2、在Startup.cs
中配置
You need to configure OSSService in your Startup.cs:
//default minio
//添加默认对象储存配置信息
services.AddOSSService(option =>
{
option.Provider = OSSProvider.Minio;
option.Endpoint = "oss.oncemi.com:9000";
option.AccessKey = "Q*************9";
option.SecretKey = "A**************************Q";
option.IsEnableHttps = true;
option.IsEnableCache = true;
});
//aliyun oss
//添加名称为‘aliyunoss’的OSS对象储存配置信息
services.AddOSSService("aliyunoss", option =>
{
option.Provider = OSSProvider.Aliyun;
option.Endpoint = "oss-cn-hangzhou.aliyuncs.com";
option.AccessKey = "L*******************U";
option.SecretKey = "5*******************************T";
option.IsEnableCache = true;
});
//qcloud oss
//也可以从配置文件中加载节点为‘OSSProvider’的配置信息
services.AddOSSService("QCloud", "OSSProvider");
可注入多个OSSService,不同的Service用名称来区分。需要注意的是,腾讯云COS中配置节点Endpoint表示AppId。
appsettings.json配置文件实例:
{
"OSSProvider": {
"Provider": "QCloud", //枚举值支持:Minio/Aliyun/QCloud
"Endpoint": "你的AppId", //腾讯云中表示AppId
"Region": "ap-chengdu", //地域
"AccessKey": "A****************************z",
"SecretKey": "g6I***************la",
"IsEnableCache": true //是否启用缓存,推荐开启
}
}
3、使用Demo
/// <summary>
/// 使用默认的配置文件
/// </summary>
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IOSSService _OSSService;
private readonly string _bucketName = "default-dev";
public HomeController(ILogger<HomeController> logger
, IOSSService OSSService)
{
_logger = logger;
_OSSService = OSSService;
}
}
/// <summary>
/// 获取IOSSServiceFactory,根据名称创建对应的OSS服务
/// </summary>
public class QCloudController : Controller
{
private readonly ILogger<QCloudController> _logger;
private readonly IOSSService _OSSService;
private readonly string _bucketName = "default-dev";
public QCloudController(ILogger<QCloudController> logger
, IOSSServiceFactory ossServiceFactory)
{
_logger = logger;
_OSSService = ossServiceFactory.Create("QCloud");
}
}
列出bucket中的全部文件
public async Task<IActionResult> ListBuckets()
{
try
{
var result = await _OSSService.ListBucketsAsync();
return Json(result);
}
catch (Exception ex)
{
return Content(ex.Message);
}
}
配置参数
名称 | 类型 | 说明 | 案例 | 备注 |
---|---|---|---|---|
Provider | 枚举 | OSS提供者 | Minio | 允许值:Minio,Aliyun, QCloud |
Endpoint | string | 节点 | oss-cn-hangzhou.aliyuncs.com | 在腾讯云OSS中表示AppId |
AccessKey | string | AccessKey | F...............s | |
SecretKey | string | SecretKey | v...............d | |
Region | string | 地域 | ap-chengdu | |
IsEnableHttps | bool | 是否启用HTTPS | true | 建议启用 |
IsEnableCache | bool | 是否启用缓存 | true | 启用后将缓存签名URL,以减少请求次数 |
Dependencies
- Aliyun.OSS.SDK.NetCore
- Microsoft.Extensions.Caching.Memory
- Newtonsoft.Json
- Tencent.QCloud.Cos.Sdk
To do list
- 修改签名URL过期策略为滑动过期策略
- 文件分页加载
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Aliyun.OSS.SDK.NetCore (>= 2.13.0)
- BceSdkDotNetCore (>= 1.0.2.911)
- Microsoft.AspNetCore.StaticFiles (>= 2.2.0)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.4)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
- Minio (>= 5.0.0)
- Qiniu (>= 8.3.1)
- Tencent.QCloud.Cos.Sdk (>= 5.4.34)
NuGet packages (43)
Showing the top 5 NuGet packages that depend on OnceMi.AspNetCore.OSS:
Package | Downloads |
---|---|
BLT.Common
Package Description |
|
BLT.ServiceFabric
Package Description |
|
Mall3s.ServiceFabric
Package Description |
|
Furion.Extras.Admin.NET
基于Furion框架实现的通用权限管理平台应用层框架。前后端分离,开箱即用。 仓库地址:https://gitee.com/zuohuaijun/Admin.NET,包括前后端完整源码。 |
|
Mall3s.Common
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on OnceMi.AspNetCore.OSS:
Repository | Stars |
---|---|
oncemi/OnceMi.Framework
基于.NET 7和Vue 2开发的企业级前后端分离权限管理开发框架(后台管理系统),具有组织管理、角色管理、用户管理、菜单管理、授权管理、计划任务、文件管理等功能。支持国内外多种流行数据库,支持IdentityServer4认证中心。
|
|
leooneone/aibpm.plus
AIBPM是一个开源的工作流引擎。本项目是后端服务,前端请移步aibpm.ui.plus。
|
Version | Downloads | Last updated |
---|---|---|
1.2.0 | 32,801 | 8/9/2023 |
1.1.9 | 82,453 | 10/20/2022 |
1.1.8 | 7,556 | 8/15/2022 |
1.1.7 | 593 | 8/13/2022 |
1.1.6 | 37,843 | 7/10/2022 |
1.1.5 | 6,821 | 5/6/2022 |
1.1.4 | 18,666 | 3/5/2022 |
1.1.3 | 543 | 3/4/2022 |
1.1.1 | 9,035 | 12/26/2021 |
1.1.0 | 69,695 | 12/13/2021 |
1.0.9 | 22,916 | 9/12/2021 |
1.0.8 | 25,366 | 8/7/2021 |
1.0.7 | 429 | 8/7/2021 |
1.0.6 | 1,030 | 8/1/2021 |
1.0.5 | 767 | 7/29/2021 |
1.0.4 | 25,891 | 6/21/2021 |
1.0.3 | 6,505 | 5/7/2021 |
1.0.2 | 832 | 12/30/2020 |
1. 更新依赖nuget包;2. 添加天翼云支持(by cxwos)