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