C# 上傳本地視頻到七牛雲服務器

第一步添加DLL引用ide

Install-Package Newtonsoft.Jsonspa

Install-Package Qiniucode

   #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); blog

其中s爲文件的路徑string

相關文章
相關標籤/搜索