牛腩博客
vget version error.

  • 菜单
  • 日历
    coding.net LinkedIn Email
    • 2025年01月 (213)
    • 2025年02月 (121)
    • 2025年03月 (231)
    • 2025年04月 (311)
    • 2025年05月 (450)
    • 2025年06月 (186)
    • 2025年07月 (36)

    不知道什么意思

    牛腩博客

    按分类查询
    github LinkedIn Email
    2023-11-10 10:50

    NET7下传图片到七牛云上

    NET7下传图片到七牛云上

    2023年11月10日记录一下,在自己的商品库项目里用到的,之前的代码没有关闭文件流,导致想在上传到七牛云后再删除本地图片就报错了,删除不了,改了一下,关闭了文件流,然后就可以删除了,记得引用nuget: Qiniu.SDK



    //using Qiniu.Util;
    //using Qiniu.Storage;
    string AccessKey = "WB-23oGbtMRULmI1n5345320zbdk2O";
    string SecretKey = "cJRT2FAUG9nsG25325326nu3x27nz3D";
    string Bucket = "niunan-net";
    Mac mac = new Mac(AccessKey, SecretKey);
    PutPolicy putPolicy = new PutPolicy();
    putPolicy.Scope = Bucket;
    putPolicy.SetExpires(3600);
    string jstr = putPolicy.ToJsonString();
    string token = Auth.CreateUploadToken(mac, jstr);
    Config config = new Config();
    config.Zone = Zone.ZoneCnSouth;
    config.UseHttps = false;
    config.UseCdnDomains = true;
    FormUploader fu = new FormUploader(config);
    Stream s = new System.IO.FileInfo(tpath).OpenRead();
    var result = await fu.UploadStream(s, filename_upload, token, null);
    s.Dispose();
    s.Close();
    log.Info($"上传图片到七牛云,文件名【{filename_upload}】,上传结果\r\n{result.Text}\r\n\r\n\r\n");

    • ASP.NET Core
    版权所有 © 2017 www.niunan.net
    Powered by niunan