Skip to content

Commit 7ad12ef

Browse files
committed
fix(system/file): 修复上传文件不指定 parentPath 默认上级目录不自动创建的问题
1 parent e4f4554 commit 7ad12ef

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

continew-system/src/main/java/top/continew/admin/system/controller/FileController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class FileController extends BaseController<FileService, FileResp, FileRe
6060
/**
6161
* 上传文件
6262
* <p>
63-
* 公共上传文件请使用 {@link top.continew.admin.controller.common.CommonController#upload}
63+
* 公共上传文件请使用 {@link CommonController#upload}
6464
* </p>
6565
*
6666
* @param file 文件
@@ -69,7 +69,7 @@ public class FileController extends BaseController<FileService, FileResp, FileRe
6969
* @throws IOException /
7070
*/
7171
@Operation(summary = "上传文件", description = "上传文件")
72-
@Parameter(name = "parentPath", description = "上级目录", example = "/", in = ParameterIn.QUERY)
72+
@Parameter(name = "parentPath", description = "上级目录(默认:/yyyy/MM/dd)", example = "/", in = ParameterIn.QUERY)
7373
@SaCheckPermission("system:file:upload")
7474
@PostMapping("/upload")
7575
public FileUploadResp upload(@NotNull(message = "文件不能为空") @RequestPart MultipartFile file,

continew-system/src/main/java/top/continew/admin/system/service/FileService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package top.continew.admin.system.service;
1818

19+
import cn.hutool.core.util.StrUtil;
1920
import org.dromara.x.file.storage.core.FileInfo;
2021
import org.springframework.web.multipart.MultipartFile;
2122
import top.continew.admin.common.base.service.BaseService;
@@ -60,7 +61,7 @@ default FileInfo upload(MultipartFile file) throws IOException {
6061
* @throws IOException /
6162
*/
6263
default FileInfo upload(MultipartFile file, String parentPath) throws IOException {
63-
return upload(file, parentPath, null);
64+
return upload(file, StrUtil.blankToDefault(parentPath, getDefaultParentPath()), null);
6465
}
6566

6667
/**
@@ -94,7 +95,7 @@ default FileInfo upload(File file) throws IOException {
9495
* @throws IOException /
9596
*/
9697
default FileInfo upload(File file, String parentPath) throws IOException {
97-
return upload(file, parentPath, null);
98+
return upload(file, StrUtil.blankToDefault(parentPath, getDefaultParentPath()), null);
9899
}
99100

100101
/**

continew-system/src/main/java/top/continew/admin/system/service/impl/FileServiceImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,16 @@ public void finish() {
252252
* 处理路径
253253
*
254254
* <p>
255-
* 1.如果 path 为空,则使用 {@link FileService#getDefaultParentPath()} 作为默认值 <br />
256-
* 2.如果 path 为 {@code /},则设置为空 <br />
257-
* 3.如果 path 不以 {@code /} 结尾,则添加后缀 {@code /} <br />
258-
* 4.如果 path 以 {@code /} 开头,则移除前缀 {@code /} <br />
255+
* 1.如果 path 为 {@code /},则设置为空 <br />
256+
* 2.如果 path 不以 {@code /} 结尾,则添加后缀 {@code /} <br />
257+
* 3.如果 path 以 {@code /} 开头,则移除前缀 {@code /} <br />
259258
* 示例:yyyy/MM/dd/
260259
* </p>
261260
*
262261
* @param path 路径
263262
* @return 处理路径
264263
*/
265264
private String pretreatmentPath(String path) {
266-
if (StrUtil.isBlank(path)) {
267-
return this.getDefaultParentPath();
268-
}
269265
if (StringConstants.SLASH.equals(path)) {
270266
return StringConstants.EMPTY;
271267
}

0 commit comments

Comments
 (0)