需要引入Qinu的包
appid,和appkey申请注册的时候会有
Bucket = “kettle1” 这个是在上面新建的空间名。
// See https://aka.ms/new-console-template for more information
using Qiniu.Http;
using Qiniu.Storage;
using Qiniu.Util;
Mac mac = new Mac("appid", "appkey");
//PutPolicy putPolicy = new PutPolicy();
//putPolicy.Scope = "kettle1";
//string token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
// 上传文件名
string key = "key";
// 本地文件路径
string filePath = "D:\\download\\screenrecorder_651E0D55.exe";
// 存储空间名
string Bucket = "kettle1";
// 设置上传策略
PutPolicy putPolicy = new PutPolicy();
// 设置要上传的目标空间
putPolicy.Scope = Bucket;
// 上传策略的过期时间(单位:秒)
putPolicy.SetExpires(3600);
// 文件上传完毕后,在多少天后自动被删除
putPolicy.DeleteAfterDays = 1;
// 生成上传token
string token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
Config config = new Config();
// 设置上传区域
config.Zone = Zone.ZONE_CN_East;
// 设置 http 或者 https 上传
config.UseHttps = true;
config.UseCdnDomains = true;
config.ChunkSize = ChunkUnit.U512K;
// 表单上传
FormUploader target = new FormUploader(config);
HttpResult result = target.UploadFile(filePath, key, token, null);
Console.WriteLine("form upload result: " + result.ToString());
Console.WriteLine("Hello, World!");