|
@@ -165,7 +165,7 @@ public class FileServiceImpl implements FileService {
|
|
|
targetFile.getParentFile().mkdirs();
|
|
targetFile.getParentFile().mkdirs();
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- FileUtils.write(targetFile.getAbsolutePath(), file.getBytes());
|
|
|
|
|
|
|
+ FileUtils.write(targetFile.getAbsolutePath(), file.getBytes(), true);
|
|
|
return "成功上传文件至:" + targetFile.getPath();
|
|
return "成功上传文件至:" + targetFile.getPath();
|
|
|
} catch (IllegalStateException | IOException | ReportException e) {
|
|
} catch (IllegalStateException | IOException | ReportException e) {
|
|
|
logger.error("", e);
|
|
logger.error("", e);
|
|
@@ -186,23 +186,22 @@ public class FileServiceImpl implements FileService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
- for (MultipartFile file : files) {
|
|
|
|
|
- targetFile = new File(targetFile.getParent() + "/" + file.getOriginalFilename());
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (MultipartFile file : files) {
|
|
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
|
|
+ targetFile = new File(targetFile.getParent() + "/" + fileName);
|
|
|
// 不能使用file.transferTo(targetFile),
|
|
// 不能使用file.transferTo(targetFile),
|
|
|
// 因为在spring boot下上传文件时会对临时路径进行处理,
|
|
// 因为在spring boot下上传文件时会对临时路径进行处理,
|
|
|
// 导致最终文件路径不正确,如果手动设置临时路径为根路径,
|
|
// 导致最终文件路径不正确,如果手动设置临时路径为根路径,
|
|
|
// 又会因为权限问题导致文件写入失败,
|
|
// 又会因为权限问题导致文件写入失败,
|
|
|
// 所以自己在指定路径创建文件,而不使用transferTo方法
|
|
// 所以自己在指定路径创建文件,而不使用transferTo方法
|
|
|
- FileUtils.write(targetFile.getAbsolutePath(), file.getBytes());
|
|
|
|
|
- stringBuilder.append("成功上传文件至:");
|
|
|
|
|
- } catch (IllegalStateException | IOException | ReportException e) {
|
|
|
|
|
- logger.error("", e);
|
|
|
|
|
- stringBuilder.append("上传文件失败:");
|
|
|
|
|
|
|
+ FileUtils.write(targetFile.getAbsolutePath(), file.getBytes(), true);
|
|
|
|
|
+ stringBuilder.append("上传成功:").append(fileName).append("\n");
|
|
|
}
|
|
}
|
|
|
- stringBuilder.append(targetFile.getPath()).append("\n");
|
|
|
|
|
|
|
+ return stringBuilder.toString();
|
|
|
|
|
+ } catch (IllegalStateException | IOException e) {
|
|
|
|
|
+ throw new ReportException(e).setDetailedMessage(e);
|
|
|
}
|
|
}
|
|
|
- return stringBuilder.toString();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|