diff --git a/main/java/shkd/utils/AttachmentFileUtil.java b/main/java/shkd/utils/AttachmentFileUtil.java index 2a4a091..afb834e 100644 --- a/main/java/shkd/utils/AttachmentFileUtil.java +++ b/main/java/shkd/utils/AttachmentFileUtil.java @@ -121,7 +121,7 @@ public class AttachmentFileUtil { * @param attachKey 附件面板标识 * @param dirpath 文件目录路径 * @param filenames 文件名称集合 - * @throws IOException + * @author yuxueliang */ public static boolean saveDirFile2Attchment(String appId, String entity, Object pk, String dirpath, String attachKey, JSONArray filenames) throws Exception { logger.info("传入的文件夹路径"+dirpath); @@ -135,10 +135,13 @@ public class AttachmentFileUtil { TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); InputStream inputs; FileService service = FileServiceFactory.getAttachmentFileService(); + int filesize = 0; //遍历目标目录,得到所有文件 for (int i = 0; i < filenames.size(); i++) { destFile = filenames.getJSONObject(i); attachments.clear(); +// service = FileServiceFactory.getAttachmentFileService(); +// cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); fileName = destFile.getString("fileName");//文件名称可能涉及字符集转义,需要注意 attachItem = new HashMap<>(); //附件编号 如果不设置,在前台删除某一个文件时,会把所有编号为空的都删掉 @@ -146,16 +149,19 @@ public class AttachmentFileUtil { //文件名称 attachItem.put("name", fileName); logger.info("文件名称"+fileName); -// service = FileServiceFactory.getAttachmentFileService(); inputs = service.getInputStream(dirpath+"/"+fileName); // inputs = service.getInputStream("E:\\dobews\\dobe_cosmic6\\replay_pid13348.log"); - logger.info("文件大小"+inputs.available()); -// cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); - //将文件流存入临时文件缓存(拷贝完成)(最后一个参数为缓存有效期,600秒) - tempUrl = cache.saveAsUrl(fileName, inputs, 600); +// logger.info("文件大小"+inputs.available());//Linux服务器上此方法不能返回文件大小,都是0 //文件大小 -// attachItem.put("size", ByteStreams.toByteArray(inputs).length); - attachItem.put("size", 60000); + filesize = ByteStreams.toByteArray(inputs).length; + attachItem.put("size", filesize); + logger.info("文件大小"+filesize); + if(filesize == 0){ + attachItem.put("size", 60000); + } + //将文件流存入临时文件缓存(拷贝完成)(最后一个参数为缓存有效期,600秒) + tempUrl = cache.saveAsUrl(fileName, inputs, 600);//此方法执行后inputs会被自动关闭,后续不能再对inputs操作 + //修改时间 attachItem.put("lastModified",System.currentTimeMillis()); logger.info("文件临时路径"+tempUrl);