|
|
|
@ -3,6 +3,7 @@ package com.zdxt.enforcementcode.service.common.impl; |
|
|
|
|
|
|
|
import com.zdxt.enforcementcode.common.config.RuoYiConfig; |
|
|
|
import com.zdxt.enforcementcode.common.util.file.FileUploadUtils; |
|
|
|
import com.zdxt.enforcementcode.common.util.file.MimeTypeUtils; |
|
|
|
import com.zdxt.enforcementcode.service.common.FileUploadApi; |
|
|
|
import org.dromara.common.core.exception.base.BaseException; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -22,6 +23,7 @@ public class FileUploadApiImpl implements FileUploadApi { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
RuoYiConfig ruoYiConfig; |
|
|
|
|
|
|
|
@Override |
|
|
|
public String upload(MultipartFile file) { |
|
|
|
String filePath = RuoYiConfig.getUploadPath(); |
|
|
|
@ -32,4 +34,26 @@ public class FileUploadApiImpl implements FileUploadApi { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String uploadWithType(MultipartFile file, String dir) { |
|
|
|
try { |
|
|
|
// 构建完整的上传路径:基础路径 + 指定目录
|
|
|
|
String basePath = RuoYiConfig.getUploadPath(); |
|
|
|
String uploadPath; |
|
|
|
|
|
|
|
if (dir != null && !dir.isEmpty()) { |
|
|
|
// 去除目录前后的斜杠,避免路径问题
|
|
|
|
String cleanDir = dir.trim().replaceAll("^/+|/+$", ""); |
|
|
|
uploadPath = basePath + "/" + cleanDir; |
|
|
|
} else { |
|
|
|
// 如果未指定目录,使用默认上传路径
|
|
|
|
uploadPath = basePath; |
|
|
|
} |
|
|
|
|
|
|
|
return FileUploadUtils.upload(uploadPath, file); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new BaseException("上传失败: " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|