easyui filebox 檔案上傳

來源:互聯網
上載者:User

標籤:stat   下載   nmap   file   命名   original   ssi   substring   https   

@RequestMapping(value = "saveFileupload")
@ResponseBody
public String saveFileupload(HttpServletRequest request,String menutree,HttpServletResponse response){
String fileName="";
String docType="";
//建立一個通用的多部分解析器
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
//判斷 request 是否有檔案上傳,即多部分請求
if(multipartResolver.isMultipart(request)){
//轉換成多部分request
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;
//取得request中的所有檔案名稱
Iterator<String> iter = multiRequest.getFileNames();

while(iter.hasNext()){
//取得上傳檔案
MultipartFile file = multiRequest.getFile(iter.next());
if(file != null){
//取得當前上傳檔案的檔案名稱
String priNames = file.getOriginalFilename();
String priName=priNames.substring(0,priNames.indexOf("."));
if(!"".equals(priName)){
//重新命名上傳後的檔案名稱

excelFile = new File(filePath+""+priNames);
docType = priNames.substring((priNames.lastIndexOf(".")));
fileUploadService.savefile(priName, filePath, docType, menutree);
try {
file.transferTo(excelFile);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}



return JsonMapper.getInstance().toJson("操作成功");
}

/*
* 檔案下載
*/
@RequestMapping(value = "downFile")
@ResponseBody
public void downFile(String id,HttpServletRequest request,HttpServletResponse response){

List<Map<String,Object>> list=fileUploadService.downFile(id);
String filetype=String.valueOf(list.get(0).get("filetype"));
try{

//File file = new File(Constant.OPLOAD_PAHT,fileName);
// 讀到流中
InputStream inStream = new FileInputStream(list.get(0).get("filecontent")+""+list.get(0).get("filename")+""+""+filetype+"");// 檔案的存放路徑
// 設定輸出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(list.get(0).get("filename")+filetype,"UTF-8"));
// 迴圈取出流中的資料
byte[] b = new byte[1000];
int len;

while ((len = inStream.read(b)) > 0)
response.getOutputStream().write(b, 0, len);
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}

 

easyui filebox 檔案上傳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.