前臺下載 ...
/** * * 下載文件 * * @param id */ @RequestMapping(value="/downloadFile") public void downloadFile(String id, HttpServletRequest request, HttpServletResponse response) { //文件頭信息 FileInfo fileinfo = licBO.findFileInfo(id); if(fileinfo == null) { return; } String fileName = fileinfo.getFilename(); String path = licBO.findFilePath(id)+fileinfo.getFiletype(); response.setContentType("video/mpeg4; charset=utf-8"); // 定義輸出文件頭 try { response.setHeader("Content-Disposition", "attachment;filename=\"" + URLEncoder.encode(fileName,"UTF-8") + "\""); File file = new File(path); int len = (int) file.length(); byte[] buf = new byte[4096]; FileInputStream fis = new FileInputStream(file); OutputStream out = response.getOutputStream(); len = fis.read(buf); while (len != -1) { out.write(buf, 0, len); len = fis.read(buf); } out.flush(); out.close(); fis.close(); } catch (Exception e) { // TODO 自動生成 catch 塊 logger.error(this, e); } }
前臺下載
window.top.showPic(URLS.filedownloadurl+'?id='+uploadobj[parentxxbh]);