1. 程式人生 > >非同步上傳檔案使用new FormData($(‘#uploadForm‘)[0])序列化表單

非同步上傳檔案使用new FormData($(‘#uploadForm‘)[0])序列化表單

/// <summary>///     上傳新圖片,(包含檔案上傳)
        /// </summary>/// <returns></returns>public JsonResult UpLoad()
        {
            if (null != Session[Consts.SYSTEMUERSESSION])
            {
                string pictureName = Request["videoTitle"];//圖片標題string pictureInfoUrl = "";//圖片上傳之後的虛擬路徑
string pictureCategoryKey = Request["PictureCategoryList"];//視訊分類外來鍵ID FileUpLoadResult fileUpLoadPicture = null;//用於輸出結果string fileSavePath = Consts.PICTURESAVEPATH + DateTime.Now.ToString("yyyyMMdd") + "/";//當天時間最為資料夾string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");//生成的檔名稱
//上傳,如果是視屏檔案,自動生成 接切圖 fileUpLoadPicture = Request.UpLoad(fileSavePath, null, "", fileName, ""); #region 裝箱、入庫 if (fileUpLoadPicture.FileSavePath != null) { foreach (var path in fileUpLoadPicture.FileSavePath) { pictureInfoUrl
+= (path + ","); } pictureInfoUrl = pictureInfoUrl.Remove(pictureInfoUrl.Length - 1, 0); ColumnPicture picture = new ColumnPicture() { Id = CombHelper.NewComb(), PictureTitle = pictureName, PictureTitleDescription = pictureInfoUrl, GoodClickTimes = 888, BadClickTimes = 10, AddDate = DateTime.Now, FavoriteTimes = 888, IsEnabled = true, ToTop = 0, CustomerKey = ((Customer)Session[Consts.SYSTEMUERSESSION]).Id, ColumnsCategoryKey = new Guid(pictureCategoryKey) }; if (_pictureService.Insert(picture)) { fileUpLoadPicture = new FileUpLoadResult() { Status = true, FileSavePath = null, ErrorMsg = "" }; } } #endregionreturn Json(fileUpLoadPicture, JsonRequestBehavior.AllowGet); } return null; }