1. 在appsettings.json中添加存储配置
//存储配置
  "Storage": [
    {
      "Name": "qiniu",
      "UploadTokenUrl": "https://localhost:5001/storage/uptoken?provider=qiniu",
      "AccessKey": "your ak",
      "SecretKey": "your sk",
      "Domain": "http://res.tthongbao.cn", //云存储域名
      "Bucket": "rsyunpan",
      "Zone": "ZONE_CN_South", //华东 ZONE_CN_East  华北 ZONE_CN_North 华南 ZONE_CN_South  北美 ZONE_US_North
      "UploadTokenExpireTime": 30, // 上传token有效时间单位:秒
      "DownloadTokenExpireTime": 5, //下载token有效时间
      "ManageTokenExpireTime": 5 //管理token有效时间
    },
    {
      "Name": "qiniu",
      "UploadTokenUrl": "https://localhost:5001/storage/uptoken?provider=qiniu",
      "AccessKey": "your ak",
      "SecretKey": "your sk",
      "Domain": "http://res.rscode.cn", //云存储域名
      "Bucket": "res-rscode-cn",
      "Zone": "ZONE_CN_East", //华东 ZONE_CN_East  华北 ZONE_CN_North 华南 ZONE_CN_South  北美 ZONE_US_North
      "UploadTokenExpireTime": 30, // 上传token有效时间单位:秒
      "DownloadTokenExpireTime": 5, //下载token有效时间
      "ManageTokenExpireTime": 5 //管理token有效时间
    }
  ]
2. 配置服务
services.AddQiniuStorage(Configuration);
3. 调用IStorageProvider

3.1注入

IEnumerable<IStorageProvider> providers

3.2实例存储对象

var qiniu = providers.FirstOrDefault(s => s.StorageName == "qiniu")

3.3指定存储区

qiniu.UseBucket("rsyunpan");

实例代码

[Authorize]
[HttpGet("uptoken")]
public async Task<object> UpToken([FromServices] IEnumerable<IStorageProvider> providers,string key, string provider = "qiniu")
{
    var userId = User.Claims.FirstOrDefault(x => x.Type == "UserId")?.Value;
    var qiniu = providers.FirstOrDefault(s => s.StorageName == provider);

    qiniu.UseBucket("rsyunpan");
    var tokenInfo =await qiniu.GetUploadTokenInfoAsync(key,DateTime.Now.AddMinutes(5));

    return tokenInfo;
}

七牛图缩图 https://developer.qiniu.com/dora/1279/basic-processing-images-imageview2

results matching ""

    No results matching ""