public JsonResult SaveBigFileInit() { try { _log.Debug("SaveBigFileInit Start"); SaveBigFileInitModel model = new SaveBigFileInitModel() { FileName = CommonHelper.DecodeUrl(Request.Form["FileName"]), Docid = CommonHelper.DecodeUrl(Request.Form["Docid"]), TokenId = CommonHelper.GetToken(Request.Form["TokenId"]), Ondup = Convert.ToInt64(Request.Form["Ondup"]), Length = Convert.ToInt64(Request.Form["FileLength"]) }; _log.Debug($"SaveBigFileInit: {model.FileName}"); IAS7APIHelper helper = new AS7APIHelper(); var uploadFileRes = helper.UploadBigFileInit(model); if (uploadFileRes.ErrorCode == 403002039) { uploadFileRes.FileName = helper.GetSuggestFileName(model.TokenId, model.Docid, model.FileName); } _log.Debug("SaveBigFileInit End"); return(Json(new JsonModel { Success = true, StatusCode = uploadFileRes.ErrorCode, Data = JsonConvert.SerializeObject(uploadFileRes) })); } catch (Exception ex) { _log.Debug($"SaveBigFileToServer Exception: {ex.Message}"); return(Json(new JsonModel { Success = false, Message = ex.Message })); } }
/// <summary> /// 大文件上传开始 /// </summary> /// <param name="model">SaveBigFileInitModel</param> public UploadFileRes UploadBigFileInit(SaveBigFileInitModel model) { UploadFileRes uploadFileRes = new UploadFileRes(); try { var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return(true); }; using (var httpClient = new HttpClient(handler)) { httpClient.DefaultRequestHeaders.Add("Authorization", model.TokenId); // 文件body var json = "{\"docid\":\"" + model.Docid + "\",\"name\":\"" + model.FileName + "\",\"length\":" + model.Length + ",\"ondup\":" + model.Ondup + "}"; var content = new StringContent(json, Encoding.UTF8, "application/json"); var res = httpClient.PostAsync($"{Constant.OAuth2Url}/api/efast/v1/file/osinitmultiupload", content).Result; var resStr = res.Content.ReadAsStringAsync().Result; int resCode = (int)res.StatusCode; // 若为错误返回码则抛出异常 if (resCode < 200 || resCode >= 300) { var errModel = JsonConvert.DeserializeObject <ErrorModel>(resStr); _log.Debug($"UploadBigFile Osinitmultiupload Exception: {errModel.cause}, Code: {errModel.code}"); uploadFileRes.ErrorDetail = JsonConvert.SerializeObject(errModel.detail); uploadFileRes.ErrorCode = errModel.code; return(uploadFileRes); } var uModel = JsonConvert.DeserializeObject <BeginUploadModel>(resStr); uploadFileRes.FileName = JsonConvert.SerializeObject(uModel); } return(uploadFileRes); } catch (Exception ex) { _log.Debug($"UploadBigFile Exception: {ex.Message}"); throw ex; } }