七牛云-C#SDK-上传-前期准备

1.创建一个asp.net core MVC 程序(这里随便

    这是一个空的程序

    

2.创建UploadController

3.添加引用

Install-Package Newtonsoft.Json //用来处理json
Install-Package Qiniu //七牛云

4.获取七牛云上传的配置信息   AK & SK & Bucket

AK & SK : 个人中心------>密钥管理

 Bucket:就是创建对象存储空间时取的名字

把上面的配置信息放在appsetting.json中,方便读取 

下面的配置还有一个单独提出来的链接:https://www.cnblogs.com/mi21/p/10907948.html

5.在appsetting.json 文件中添加自定义配置

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",

  "Qny": {
    "qiniuyunAK": "AK", //ak
    "qiniuyunSK": "SK", //sk
    "qiniuyunBucket": "空间名称", //存储空间名称
    "prefixPath": "http://upload.qiniup.com" //七牛云地址
  }
}

6.创建一个Model 

public class QnySetting
    {
        public string qiniuyunAK { get; set; }
        public string qiniuyunSK { get; set; }
        public string qiniuyunBucket { get; set; }
        public string prefixPath { get; set; }
    }

7.在Startup.cs中注册服务

services.Configure<QnySetting>(this.Configuration.GetSection("Qny"));

8.在xxxcontroller中使用

private readonly QnySetting _Quy;
        public UploadController(IOptions<QnySetting> Quy)
        {
            _Quy = Quy.Value;
        }
        public IActionResult Index()
        {
            Console.WriteLine(_Quy);
            return View();
        }

 到这里前期的准备就完了,继续了解请看:https://www.cnblogs.com/mi21/p/10908194.html 

原文地址:https://www.cnblogs.com/mi21/p/10904689.html