🐛 文件上传问题修复

This commit is contained in:
ronger 2022-01-14 13:47:28 +08:00
parent d9bbc49b37
commit 53a6313fdc

View File

@ -189,7 +189,7 @@ public class UploadController {
String fileName = System.currentTimeMillis() + fileType; String fileName = System.currentTimeMillis() + fileType;
String savePath = file.getPath() + File.separator + fileName; String savePath = file.getPath() + File.separator + fileName;
File saveFile = new File(savePath); File saveFile = new File(savePath);
try (InputStream in = multipartFiles[i].getInputStream(); OutputStream out = Files.newOutputStream(saveFile.toPath())) { try (InputStream in = multipartFile.getInputStream()) {
String md5 = DigestUtils.md5DigestAsHex(in); String md5 = DigestUtils.md5DigestAsHex(in);
String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser(), fileType); String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser(), fileType);
if (StringUtils.isNotEmpty(fileUrl)) { if (StringUtils.isNotEmpty(fileUrl)) {
@ -197,7 +197,7 @@ public class UploadController {
continue; continue;
} }
fileUrl = localPath + fileName; fileUrl = localPath + fileName;
FileCopyUtils.copy(in, out); FileCopyUtils.copy(multipartFile.getBytes(), saveFile);
forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser(), multipartFile.getSize(), fileType); forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser(), multipartFile.getSize(), fileType);
successMap.put(orgName, localPath + fileName); successMap.put(orgName, localPath + fileName);
} catch (IOException e) { } catch (IOException e) {