|
|
@@ -104,7 +104,7 @@ public class FileServiceImpl implements FileService {
|
|
|
logger.error(message);
|
|
|
return message;
|
|
|
}
|
|
|
- if (file == null || file.isEmpty()) {
|
|
|
+ if (file == null) {
|
|
|
message = "文件为空,无法进行上传!";
|
|
|
logger.error(message);
|
|
|
return message;
|
|
|
@@ -147,46 +147,40 @@ public class FileServiceImpl implements FileService {
|
|
|
return message;
|
|
|
} catch (IllegalStateException | IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ message = "上传文件失败: " + fileName;
|
|
|
+ logger.error(message);
|
|
|
+ return message;
|
|
|
}
|
|
|
-
|
|
|
- message = "上传文件失败: " + fileName;
|
|
|
- logger.error(message);
|
|
|
- return message;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String upload(String filePath, Boolean isAbsolutePath, MultipartFile file) {
|
|
|
+ public String upload(String filePath, Boolean isAbsolutePath, MultipartFile[] files) {
|
|
|
logger.info("request... " + filePath);
|
|
|
- String message;
|
|
|
- if (file == null || file.isEmpty()) {
|
|
|
+ String message = "";
|
|
|
+ if (ArrayUtils.isEmpty(files)) {
|
|
|
message = "文件为空,无法进行上传!";
|
|
|
logger.error(message);
|
|
|
return message;
|
|
|
}
|
|
|
filePath = getAbsolutePath(filePath, isAbsolutePath);
|
|
|
- File targetFile = new File(filePath);
|
|
|
- // 根据所上传的文件名称创建文件
|
|
|
- if (targetFile.exists() && targetFile.isFile()) {
|
|
|
- targetFile = new File(targetFile.getParent() + "/" + file.getOriginalFilename());
|
|
|
- } else {
|
|
|
- targetFile = new File(targetFile.getPath() + "/" + file.getOriginalFilename());
|
|
|
- }
|
|
|
+ File targetFile = new File(filePath + "/" + files[0].getOriginalFilename());
|
|
|
// 检查路径是否存在
|
|
|
if (!targetFile.getParentFile().exists()) {
|
|
|
targetFile.getParentFile().mkdirs();
|
|
|
}
|
|
|
- try {
|
|
|
- file.transferTo(targetFile);
|
|
|
- message = "成功上传文件至:" + targetFile.getPath();
|
|
|
- logger.info(message);
|
|
|
- return message;
|
|
|
- } catch (IllegalStateException | IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ targetFile = new File(targetFile.getParent() + "/" + file.getOriginalFilename());
|
|
|
+ try {
|
|
|
+ file.transferTo(targetFile);
|
|
|
+ message += "成功上传文件至:" + targetFile.getPath() + "\n";
|
|
|
+ } catch (IllegalStateException | IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ message += "上传文件失败: " + targetFile.getPath() + "\n";
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- message = "上传文件失败: " + targetFile.getPath();
|
|
|
- logger.error(message);
|
|
|
+ logger.info(message);
|
|
|
return message;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|