| | |
| | | return false; |
| | | } |
| | | |
| | | // 存放在数据库中的文件,直接判定是否有值 |
| | | if (attachmentFse.getValue(CmnConst.FILE_CONTENT) != null) { |
| | | return true; |
| | | } |
| | | |
| | | //判断文件存放在服务器还是本地 |
| | | boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN)); |
| | | String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL); |
| | |
| | | if (saveInDb) { |
| | | File localFile = new File(Global.getSystemConfig("local.dir", "") + File.separator + attachmentFse.getString(CmnConst.ATTACHMENT_URL) + File.separator + fileName); |
| | | if (!localFile.exists()) { |
| | | localFile.getParentFile().mkdirs(); |
| | | Files.copy(is, localFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | } |
| | |
| | | ftpService.downloadFile(path, os); |
| | | } |
| | | } else { |
| | | // 直接在本地的目录中找文件 |
| | | String localBasePath = Global.getSystemConfig("local.dir", ""); |
| | | path = localBasePath + File.separator + path; |
| | | File file = new File(path); |
| | | int len; |
| | | byte[] b = new byte[1024]; |
| | | try (InputStream is = new FileInputStream(file)) { |
| | | InputStream is = null; |
| | | try { |
| | | Object fileContent = attachmentFse.getValue("file_content"); |
| | | boolean saveInDb = fileContent != null; |
| | | if (saveInDb) { |
| | | // 存储到数据库 |
| | | is = (InputStream) fileContent; |
| | | } else { |
| | | // 直接在本地的目录中找文件 |
| | | String localBasePath = Global.getSystemConfig("local.dir", ""); |
| | | path = localBasePath + File.separator + path; |
| | | File file = new File(path); |
| | | is = Files.newInputStream(file.toPath()); |
| | | } |
| | | int len; |
| | | byte[] b = new byte[1024]; |
| | | while ((len = is.read(b)) > 0) { |
| | | if (Global.getPropertyToBoolean("file.encrypt", "true")) { |
| | | // 需要解密 |
| | |
| | | os.write(b, 0, len); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new BaseException(FileCode.GET_FILE_BYTES_FAIL); |
| | | } finally { |
| | | if (is != null) { |
| | | is.close(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return os.toByteArray(); |
| | |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 验证是否可以预览 |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public Object checkPreview(FieldSetEntity fse) { |
| | | String fileName = fse.getString("file_name"); |
| | | boolean allowPreviewFlag = Global.getPropertyToBoolean("file.view.online", "true"); |
| | | List<String> canTransferFormatList = Lists.newArrayList(Arrays.asList(Global.getSystemConfig("can.transfer.format", "").split(","))); |
| | | List<String> canDirectPreviewList = Lists.newArrayList(Arrays.asList(Global.getSystemConfig("can.direct.view.online.format", "").split(","))); |
| | | List<String> canPreviewList = Lists.newArrayList(); |
| | | canPreviewList.addAll(canTransferFormatList); |
| | | canPreviewList.addAll(canDirectPreviewList); |
| | | if (StringUtils.isEmpty(fileName)) { |
| | | if (allowPreviewFlag) { |
| | | return BaseUtil.collection2String(canPreviewList); |
| | | } else { |
| | | return ""; |
| | | } |
| | | } else { |
| | | String tail = fileName.substring(fileName.lastIndexOf(".") + 1); |
| | | return allowPreviewFlag && canPreviewList.contains(tail); |
| | | } |
| | | } |
| | | } |