diff --git a/main/java/shkd/utils/AttachmentFileUtil.java b/main/java/shkd/utils/AttachmentFileUtil.java index 5f79837..2a4a091 100644 --- a/main/java/shkd/utils/AttachmentFileUtil.java +++ b/main/java/shkd/utils/AttachmentFileUtil.java @@ -11,6 +11,7 @@ import java.util.*; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.google.common.io.ByteStreams; import kd.bos.cache.CacheFactory; import kd.bos.cache.TempFileCache; import kd.bos.context.RequestContext; @@ -122,7 +123,7 @@ public class AttachmentFileUtil { * @param filenames 文件名称集合 * @throws IOException */ - public static boolean saveDirFile2Attchment(String appId, String entity, Object pk, String dirpath, String attachKey, JSONArray filenames) throws IOException { + public static boolean saveDirFile2Attchment(String appId, String entity, Object pk, String dirpath, String attachKey, JSONArray filenames) throws Exception { logger.info("传入的文件夹路径"+dirpath); List> attachments = new ArrayList<>(1); Map attachItem; @@ -148,12 +149,13 @@ public class AttachmentFileUtil { // service = FileServiceFactory.getAttachmentFileService(); inputs = service.getInputStream(dirpath+"/"+fileName); // inputs = service.getInputStream("E:\\dobews\\dobe_cosmic6\\replay_pid13348.log"); - //文件大小 - attachItem.put("size", ""+inputs.available()); logger.info("文件大小"+inputs.available()); // cache = CacheFactory.getCommonCacheFactory().getTempFileCache(); //将文件流存入临时文件缓存(拷贝完成)(最后一个参数为缓存有效期,600秒) tempUrl = cache.saveAsUrl(fileName, inputs, 600); + //文件大小 +// attachItem.put("size", ByteStreams.toByteArray(inputs).length); + attachItem.put("size", 60000); //修改时间 attachItem.put("lastModified",System.currentTimeMillis()); logger.info("文件临时路径"+tempUrl); @@ -162,6 +164,7 @@ public class AttachmentFileUtil { logger.info("文件正式路径"+actUrl); //将新文件的物理路径存入map attachItem.put("url", actUrl); + attachments.add(attachItem); //维护单据和附件的关系(非文件上传) AttachmentServiceHelper.upload(entity, pk, attachKey, attachments);