@RequestMapping("downloadfile") public void downLoadfile(HttpServletRequest request, HttpServletResponse response) { String unid = request.getParameter("unid"); FileUpload fileUpload = fileUploadService.selectByPrimaryKey(unid); if (fileUpload != null) { try { String filename = new String(fileUpload.getOriginalFilename().getBytes("GBK"), "ISO-8859-1"); String path = fileUpload.getPath(); response.setCharacterEncoding("utf-8"); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;fileName=" + filename); response.setHeader("Content-Length", fileUpload.getFlieSize()); InputStream inputStream = new FileInputStream(new File(path)); OutputStream os = response.getOutputStream(); byte[] b = new byte[2048]; int length; while ((length = inputStream.read(b)) > 0) { os.write(b, 0, length); } os.close(); inputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
还有一个删除方法
/** * 文件删除 * * @param request * @param response */ @ResponseBody @RequestMapping("delfile") public Map<String, Object> delfile(HttpServletRequest request, HttpServletResponse response) { String unid = request.getParameter("unid"); FileUpload fileUpload = fileUploadService.selectByPrimaryKey(unid); // 删除本地 boolean flag = false; File file = new File(fileUpload.getPath()); if (file.exists()) {// 路径为文件且不为空则进行删除 flag = file.delete(); } // 删除数据库 int result = fileUploadService.deleteByPrimaryKey(unid); if (result > 0) { flag = true; } Map<String, Object> map = new HashMap<String, Object>(); map.put("result", flag); return map; }
以上所述是小编给大家介绍的artDialog+plupload实现多文件上传,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章: