| | |
| | | |
| | | |
| | | @GetMapping("/download") |
| | | @ApiOperation(notes = "需要在地址栏测试",value = "项目过程管理-文档材料下载") |
| | | public Object download(HttpServletResponse response, @RequestParam String filePath,@RequestParam String fileName) { |
| | | Response<Object> result = new Response<>(); |
| | | File file = new File( filePath); |
| | | @ApiOperation(notes = "需要在地址栏测试 http://localhost:8090/projectManage/download?fileName=申请书.pdf",value = "项目过程管理-文档材料下载") |
| | | public String download(HttpServletResponse response, @ApiParam(value = "文件路径",required = true)@RequestParam String filePath) { |
| | | String fileName = ""; |
| | | if (filePath.length() > 10&&filePath.contains("/")) { //IP地址+文件名 |
| | | int lastIndexOf = filePath.lastIndexOf("/"); |
| | | fileName = filePath.substring(lastIndexOf); |
| | | } else { |
| | | return "filePath is Error"; |
| | | } |
| | | |
| | | String projectPath = FileUtils.getProjectPath(); |
| | | File file = new File( projectPath+fileName); |
| | | if (file.exists()) { |
| | | try { |
| | | fileName= new String(fileName.getBytes("gbk"), "ISO8859-1"); |
| | |
| | | outputStream.write(buffer, 0, i); |
| | | i = bis.read(buffer); |
| | | } |
| | | return result.setMsg(1,"下载成功"); |
| | | // return result.setMsg(1,"下载成功"); |
| | | return "downloadSuccessful"; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return result.setMsg(0,"下载失败"); |
| | | // return result.setMsg(0,"下载失败"); |
| | | return "downloadFailed"; |
| | | } finally { |
| | | if (bis != null) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | return "fileDoesNotExist"; |
| | | } |
| | | return result.setMsg(0,"文件不存在"); |
| | | } |
| | | |
| | | |