zoukankan      html  css  js  c++  java
  • C# 上传本地视频到七牛云服务器

    第一步添加DLL引用

    Install-Package Newtonsoft.Json

    Install-Package Qiniu

       #region 七牛云视频上传
            /// <summary>
            /// 七牛云视频上传
            /// </summary>
            /// <param name="fileData"></param>
            /// <returns></returns>
            [HttpPost]
            public JsonResult UploadQiniuVideo(HttpPostedFileBase fileData)
            {
                if (fileData != null)
                {
                    try
                    {
                        string SaveName = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                        Mac mac = new Mac("******************", "**********************");
                        string bucket = "csgk";
                        BinaryReader b = new BinaryReader(fileData.InputStream);
                        byte[] data = b.ReadBytes((int)fileData.InputStream.Length);
                        PutPolicy putPolicy = new PutPolicy();
                        putPolicy.Scope = bucket;
                        putPolicy.SetExpires(3600);
                        string jstr = putPolicy.ToJsonString();
                        string lic = Auth.CreateUploadToken(mac, jstr);
                        UploadManager um = new UploadManager();
                        um.UploadData(data, SaveName, lic);
                        return Json(new { Success = true, FilePath = "http://***********.com/" + SaveName, SaveName = SaveName });                
                    }
                    catch (Exception ex)
                    {
                        return Json(new { Success = false, Message = ex.Message }, JsonRequestBehavior.AllowGet);
                    }
                }
                else
                {
                    return Json(new { Success = false, Message = "请选择要上传的文件!" }, JsonRequestBehavior.AllowGet);
                }
            }
            #endregion

    若通过路径读取文件: 

    byte[] data = System.IO.File.ReadAllBytes(s); 

    其中s为文件的路径

  • 相关阅读:
    Cinema in Akiba(线段树)
    SGU
    632-掷骰子
    ZOJ
    nyoj 1129 Salvation(搜索)
    symbol table meaning
    C/C++编译和链接过程详解 (重定向表,导出符号表,未解决符号表)
    编译链接 C++
    while(cin.eof)出错 poj
    华为oj 购物单
  • 原文地址:https://www.cnblogs.com/yechangzhong-826217795/p/10984885.html
Copyright © 2011-2022 走看看