This commit is contained in:
XSWL1018 2024-06-19 09:36:23 +08:00
parent 4a5ab6b0d9
commit 8a6f6a055b
4 changed files with 17 additions and 18 deletions

View File

@ -20,12 +20,12 @@ import static com.ruoyi.common.utils.file.FileUtils.getPathFileName;
* 磁盘文件操作实现类
*/
@Component("file:strategy:disk")
public class DiskFileUtil implements FileUtil {
public class DiskFileService implements FileService {
private static String defaultBaseDir = RuoYiConfig.getProfile();
public static void setDefaultBaseDir(String defaultBaseDir) {
DiskFileUtil.defaultBaseDir = defaultBaseDir;
DiskFileService.defaultBaseDir = defaultBaseDir;
}
public static String getDefaultBaseDir() {

View File

@ -16,7 +16,7 @@ import java.io.OutputStream;
*/
public class FileOperateUtils {
private static FileUtil fileUtil = SpringUtils.getBean("file:strategy:" + RuoYiConfig.getFileServer());
private static FileService fileService = SpringUtils.getBean("file:strategy:" + RuoYiConfig.getFileServer());
/**
* 默认大小 50M
*/
@ -36,7 +36,7 @@ public class FileOperateUtils {
public static final String upload(MultipartFile file) throws IOException {
try {
FileUtils.assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
return fileUtil.upload(file);
return fileService.upload(file);
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
}
@ -53,7 +53,7 @@ public class FileOperateUtils {
*/
public static final String upload(String filePath, MultipartFile file, String[] allowedExtension) throws Exception {
FileUtils.assertAllowed(file, allowedExtension);
return fileUtil.upload(filePath, file);
return fileService.upload(filePath, file);
}
/**
@ -86,7 +86,7 @@ public class FileOperateUtils {
* @throws IOException
*/
public static final void downLoad(String fileUrl, OutputStream outputStream) throws Exception {
InputStream inputStream = fileUtil.downLoad(fileUrl);
InputStream inputStream = fileService.downLoad(fileUrl);
FileUtils.writeBytes(inputStream, outputStream);
}
@ -98,6 +98,6 @@ public class FileOperateUtils {
* @throws IOException
*/
public static final boolean deleteFile(String fileUrl) throws Exception {
return fileUtil.deleteFile(fileUrl);
return fileService.deleteFile(fileUrl);
}
}

View File

@ -9,7 +9,7 @@ import java.io.InputStream;
/**
* 文件操作接口
*/
public interface FileUtil {
public interface FileService {
/**
* 文件上传
@ -18,7 +18,7 @@ public interface FileUtil {
* @param file 文件对象
* @return 返回上传成功的文路径
* @throws IOException 比如读写文件出错时
*
*
*/
public String upload(String filePath, MultipartFile file) throws Exception;
@ -29,17 +29,17 @@ public interface FileUtil {
* @param file 文件对象
* @return 返回上传成功的文路径
* @throws IOException 比如读写文件出错时
*
*
*/
public String upload(MultipartFile file, String name) throws Exception;
/**
* 文件上传
*
*
* @param file 文件对象
* @return 返回上传成功的文路径
* @throws IOException 比如读写文件出错时
*
*
*/
public String upload(MultipartFile file) throws Exception;
@ -51,7 +51,7 @@ public interface FileUtil {
* @param file 文件对象
* @return 返回上传成功的文路径
* @throws IOException 比如读写文件出错时
*
*
*/
public String upload(String baseDir, String fileName, MultipartFile file) throws Exception;
@ -61,7 +61,7 @@ public interface FileUtil {
* @param filePath 下载的文件路径
* @return 返回上传成功的文路径
* @throws IOException 比如读写文件出错时
*
*
*/
public InputStream downLoad(String filePath) throws Exception;
@ -71,7 +71,7 @@ public interface FileUtil {
* @param filePath 删除的文件路径
* @return 返回上传成功的文路径
* @throws IOException 比如读写文件出错时
*
*
*/
public boolean deleteFile(String filePath) throws Exception;
}

View File

@ -1,9 +1,8 @@
package com.ruoyi.middleware.minio.utils;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtil;
import com.ruoyi.common.utils.file.FileService;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.middleware.minio.config.MinioConfig;
@ -18,7 +17,7 @@ import java.io.InputStream;
* Minio文件操作实现类
*/
@Component("file:strategy:minio")
public class MinioFileUtil implements FileUtil {
public class MinioFileService implements FileService {
private static MinioConfig minioConfig = SpringUtils.getBean(MinioConfig.class);
@Override