1.application.properties前端
#上傳文件大小限制spring.servlet.multipart.max-file-size=500MBspring.servlet.multipart.max-request-size=500MB
2.前端ajax
//上傳 uploadServer: function (){ todata.append("FFILE", fhFile); todata.append("PARENT_ID", this.PARENT_ID); todata.append("NAME", this.pd.NAME); todata.append("REMARKS", this.pd.REMARKS); todata.append("SHARE", this.SHARE); //發送 post 請求提交保存 $.ajax({ xhrFields: { withCredentials: true }, url: httpurl+'mfolder/upload', type: 'POST', data: todata, async: false, cache: false, contentType: false, processData: false, success: function(data){ if("success" == data.result){ $("#fok").tips({ side:2, msg:'上傳成功', bg:'#AE81FF', time:2 }); setTimeout(function(){ top.Dialog.close();//關閉彈窗 },1000); }else if("error" == data.result){ alert("上傳失敗,文件內容不能爲空!"); $("#showform").show(); $("#jiazai").hide(); }else if ("exception" == data.result){ alert("文件管理"+data.exception);//顯示異常 $("#showform").show(); $("#jiazai").hide(); } } }) },
3.後臺spring
/**上傳文件 www.1b23.com * @param * @throws Exception */ @RequestMapping(value="/upload") @RequiresPermissions("mfolder:add") @ResponseBody public Object add( @RequestParam(value="FFILE",required=false) MultipartFile file, @RequestParam(value="NAME",required=false) String NAME, @RequestParam(value="PARENT_ID",required=false) String PARENT_ID, @RequestParam(value="REMARKS",required=false) String REMARKS, @RequestParam(value="SHARE",required=false) String SHARE ) throws Exception{ Map<String,Object> map = new HashMap<String,Object>(); String errInfo = "success"; PageData pd = new PageData(); String ffile = DateUtil.getDays(), fileName = ""; if (null != file && !file.isEmpty()) { String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile; //文件上傳路徑 fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //執行上傳 pd.put("FILEPATH", Const.FILEPATHFILE + ffile + "/" + fileName); //文件路徑 pd.put("NAME", NAME); //文件名 pd.put("PARENT_ID", PARENT_ID); //目錄ID pd.put("CTIME", DateUtil.date2Str(new Date())); //建立時間 pd.put("UNAME", Jurisdiction.getName()); //上傳者,當前用戶的姓名 pd.put("MASTER", Jurisdiction.getUsername()); //用戶名 pd.put("FILESIZE", FileUtil.getFilesize(filePath + "/" + fileName)); //文件大小 pd.put("REMARKS", REMARKS); //備註 pd.put("SHARE", SHARE); //是否共享 pd.put("MFOLDER_ID", this.get32UUID()); //主鍵 mfolderService.save(pd); //存入數據庫表 }else{ errInfo = "error"; } map.put("result", errInfo); //返回結果 return map; }