ajaxfileupload 非同步下載檔案
阿新 • • 發佈:2019-01-02
@ResponseBody
@RequestMapping(value="ajaxFileUpload",method = {RequestMethod.POST,RequestMethod.GET})
public String ajaxFileUpload(Model model,HttpServletResponse response, @RequestParam MultipartFile myfile,HttpServletRequest request){
BCaseReltiveAttachment bCaseReltiveAttachment = new BCaseReltiveAttachment();
Map<String,Object> map= new HashMap<String,Object>();
if(myfile.isEmpty()){
map.put( "result", "error");
map.put( "data", bCaseReltiveAttachment);
String time1=format1.format(date1);
String houzhui = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
String changeFileName = time+houzhui; //磁碟儲存後的檔名
//獲取文件型別
String path = tAssesssmentFilePathService.findPathByType(frimType);
String type = dictService.getLabelByTypeAndValue("wdlx", frimType);
try{
//把附件放到指定目錄下
+"/";
//儲存附件資訊到,附件資訊記錄表 此操作可忽略,將檔案資訊存放在檔案表中
bCaseReltiveAttachment = bCaseReltiveAttachmentService.saveReltiveAttachments2(type,tableName,originalFilename,currentUser,genePicPath+changeFileName);
//返回頁面,附件資訊資料
map.put( "result", "success");
map.put( "data", bCaseReltiveAttachment);
//jsonStrAttachment=JsonMapper.toJsonString(bCaseReltiveAttachment);
} catch (Exception e) {
e.printStackTrace();
map.put( "result", "error");
map.put( "msg",e.getMessage());
}
}
String ret = JsonMapper.toJsonString(map);
return ret;
}
@RequestMapping(value="ajaxFileUpload",method = {RequestMethod.POST,RequestMethod.GET})
public String ajaxFileUpload(Model model,HttpServletResponse response, @RequestParam MultipartFile myfile,HttpServletRequest request){
BCaseReltiveAttachment bCaseReltiveAttachment = new BCaseReltiveAttachment();
Map<String,Object> map= new HashMap<String,Object>();
if(myfile.isEmpty()){
map.put( "result", "error");
map.put( "data", bCaseReltiveAttachment);
} else{
// 在後臺加密,讓檔名以時間命名
Date date=new Date();DateFormat format=new SimpleDateFormat("yyyyMMddHHmmss");
String
time=format.format(date);
//把檔案存放在以時間分開的資料夾內
Date date1=new Date();
DateFormat format1=new SimpleDateFormat("yyyy-MM-dd");String time1=format1.format(date1);
String originalFilename=myfile.getOriginalFilename(); //真實檔名
String changeFileName = time+houzhui; //磁碟儲存後的檔名
//獲取文件型別
String path = tAssesssmentFilePathService.findPathByType(frimType);
String type = dictService.getLabelByTypeAndValue("wdlx", frimType);
try{
//把附件放到指定目錄下
String genePicPath = "D:/jeesiteFiles/userfiles/1/files/"+path+"/"+time1
//上傳檔案
FileUtils. copyInputStreamToFile(myfile.getInputStream(), new File(genePicPath,changeFileName));//儲存附件資訊到,附件資訊記錄表 此操作可忽略,將檔案資訊存放在檔案表中
bCaseReltiveAttachment = bCaseReltiveAttachmentService.saveReltiveAttachments2(type,tableName,originalFilename,currentUser,genePicPath+changeFileName);
//返回頁面,附件資訊資料
map.put( "result", "success");
map.put( "data", bCaseReltiveAttachment);
//jsonStrAttachment=JsonMapper.toJsonString(bCaseReltiveAttachment);
} catch (Exception e) {
e.printStackTrace();
map.put( "result", "error");
map.put( "msg",e.getMessage());
}
}
String ret = JsonMapper.toJsonString(map);
return ret;
}