| | |
| | | public void download(String guid, boolean inline, HttpServletResponse res) { |
| | | try { |
| | | if (StringHelper.isEmpty(guid)) { |
| | | WebHelper.write2Page(res, NO_FILE); |
| | | WebHelper.writeStr2Page(res, NO_FILE); |
| | | return; |
| | | } |
| | | |
| | | AttachEntity entity = attachService.selectByGuid(guid); |
| | | if (entity == null) { |
| | | WebHelper.write2Page(res, NO_FILE); |
| | | WebHelper.writeStr2Page(res, NO_FILE); |
| | | return; |
| | | } |
| | | |
| | | String file = pathHelper.getConfig().getUploadPath() + File.separator + entity.getPath(); |
| | | WebHelper.download(file, entity.getName(), inline, res); |
| | | String filePath = pathHelper.getConfig().getUploadPath() + File.separator + entity.getPath(); |
| | | File file = new File(filePath); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | String msg = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, "文件不存在")); |
| | | WebHelper.writeStr2Page(res, msg); |
| | | } |
| | | |
| | | WebHelper.download(filePath, entity.getName(), inline, res); |
| | | } catch (Exception ex) { |
| | | try { |
| | | String msg = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.ERROR, "文件下载出错")); |
| | | WebHelper.write2Page(res, msg); |
| | | String msg = JSON.toJSONString(new ResponseMsg<>(HttpStatus.ERROR, "文件下载出错")); |
| | | WebHelper.writeStr2Page(res, msg); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |