From 1b2bf0fc0386c4198e86694d31bbd0d0e2be69c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AF=9B=E6=AF=9B=E8=99=AB?= <1421374934@qq.com> Date: Fri, 14 Jan 2022 15:25:38 +0800 Subject: [PATCH] :bug: fixed empty file --- .../forest/web/api/common/UploadController.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java index 98a21cd..210e1a1 100644 --- a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java +++ b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java @@ -23,10 +23,12 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.file.Files; import java.util.*; /** @@ -186,9 +188,6 @@ public class UploadController { continue; } String fileType = FileUtils.getExtend(orgName); - String fileName = System.currentTimeMillis() + fileType; - String savePath = file.getPath() + File.separator + fileName; - File saveFile = new File(savePath); try (InputStream in = multipartFile.getInputStream()) { String md5 = DigestUtils.md5DigestAsHex(in); String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser(), fileType); @@ -196,6 +195,9 @@ public class UploadController { successMap.put(orgName, fileUrl); continue; } + String fileName = System.currentTimeMillis() + fileType; + String savePath = file.getPath() + File.separator + fileName; + File saveFile = new File(savePath); fileUrl = localPath + fileName; FileCopyUtils.copy(multipartFile.getBytes(), saveFile); forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser(), multipartFile.getSize(), fileType);