OnceMi.AspNetCore.OSS 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package OnceMi.AspNetCore.OSS --version 1.0.4                
NuGet\Install-Package OnceMi.AspNetCore.OSS -Version 1.0.4                
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="OnceMi.AspNetCore.OSS" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OnceMi.AspNetCore.OSS --version 1.0.4                
#r "nuget: OnceMi.AspNetCore.OSS, 1.0.4"                
#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.
// Install OnceMi.AspNetCore.OSS as a Cake Addin
#addin nuget:?package=OnceMi.AspNetCore.OSS&version=1.0.4

// Install OnceMi.AspNetCore.OSS as a Cake Tool
#tool nuget:?package=OnceMi.AspNetCore.OSS&version=1.0.4                

OnceMi.AspNetCore.OSS

Asp.Net Core 5.0对象储存扩展包,支持Minio自建对象储存、阿里云OSS、腾讯云COS。支持OSS常规操作,比如储存桶创建,删除、对象上传、下载、生成签名URL等。目前仅支持.NET 5,也推荐升级至.NET 5.

OSS Documents

Minio: 点此查看
Aliyun: 点此查看
QCloud: 点此查看

How to use

1、Install OnceMi.AspNetCore.OSS。
CLI中安装:

dotnet add package OnceMi.AspNetCore.OSS

Nuget中安装:
Search and install OnceMi.AspNetCore.OSS in Nuget manage。

2、Configuration
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。

配置文件实例:

{
  "OSSProvider": {
    "Provider": "QCloud", //枚举值支持:Minio/Aliyun/QCloud
    "Endpoint": "你的AppId", //腾讯云中表示AppId
    "Region": "ap-chengdu",  //地域
    "AccessKey": "A****************************z",
    "SecretKey": "g6I***************la",
    "IsEnableCache": true  //是否启用缓存,推荐开启
  }
}

3、Use

/// <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);
    }
}

Option Params

名称 类型 说明 案例 备注
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
SessionToken string token 仅Minio中使用
IsEnableHttps bool 是否启用HTTPS true 建议启用
IsEnableCache bool 是否启用缓存 true 启用后将缓存签名URL,以减少请求次数

Dependencies

  1. Aliyun.OSS.SDK.NetCore
  2. MemoryCache
  3. Newtonsoft.Json
  4. Tencent.QCloud.Cos.Sdk
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (45)

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 45,657 8/9/2023
1.1.9 88,434 10/20/2022
1.1.8 7,682 8/15/2022
1.1.7 608 8/13/2022
1.1.6 41,967 7/10/2022
1.1.5 7,108 5/6/2022
1.1.4 19,691 3/5/2022
1.1.3 562 3/4/2022
1.1.1 9,588 12/26/2021
1.1.0 71,669 12/13/2021
1.0.9 23,656 9/12/2021
1.0.8 25,478 8/7/2021
1.0.7 438 8/7/2021
1.0.6 1,039 8/1/2021
1.0.5 783 7/29/2021
1.0.4 26,030 6/21/2021
1.0.3 6,538 5/7/2021
1.0.2 842 12/30/2020