🐛 文件上传问题修复

🐛 文件上传问题修复
This commit is contained in:
ronger 2022-01-14 14:20:43 +08:00 committed by GitHub
commit ffac5e7a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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) {
@ -213,7 +213,7 @@ public class UploadController {
} }
private TokenUser getTokenUser(HttpServletRequest request) throws BaseApiException { private TokenUser getTokenUser(HttpServletRequest request) throws BaseApiException {
String authHeader = request.getHeader(JwtConstants.AUTHORIZATION); String authHeader = request.getHeader(JwtConstants.UPLOAD_TOKEN);
if (StringUtils.isBlank(authHeader)) { if (StringUtils.isBlank(authHeader)) {
throw new BaseApiException(ErrorCode.UNAUTHORIZED); throw new BaseApiException(ErrorCode.UNAUTHORIZED);
} }