init
This commit is contained in:
parent
4a5ab6b0d9
commit
8a6f6a055b
@ -20,12 +20,12 @@ import static com.ruoyi.common.utils.file.FileUtils.getPathFileName;
|
|||||||
* 磁盘文件操作实现类
|
* 磁盘文件操作实现类
|
||||||
*/
|
*/
|
||||||
@Component("file:strategy:disk")
|
@Component("file:strategy:disk")
|
||||||
public class DiskFileUtil implements FileUtil {
|
public class DiskFileService implements FileService {
|
||||||
|
|
||||||
private static String defaultBaseDir = RuoYiConfig.getProfile();
|
private static String defaultBaseDir = RuoYiConfig.getProfile();
|
||||||
|
|
||||||
public static void setDefaultBaseDir(String defaultBaseDir) {
|
public static void setDefaultBaseDir(String defaultBaseDir) {
|
||||||
DiskFileUtil.defaultBaseDir = defaultBaseDir;
|
DiskFileService.defaultBaseDir = defaultBaseDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDefaultBaseDir() {
|
public static String getDefaultBaseDir() {
|
@ -16,7 +16,7 @@ import java.io.OutputStream;
|
|||||||
*/
|
*/
|
||||||
public class FileOperateUtils {
|
public class FileOperateUtils {
|
||||||
|
|
||||||
private static FileUtil fileUtil = SpringUtils.getBean("file:strategy:" + RuoYiConfig.getFileServer());
|
private static FileService fileService = SpringUtils.getBean("file:strategy:" + RuoYiConfig.getFileServer());
|
||||||
/**
|
/**
|
||||||
* 默认大小 50M
|
* 默认大小 50M
|
||||||
*/
|
*/
|
||||||
@ -36,7 +36,7 @@ public class FileOperateUtils {
|
|||||||
public static final String upload(MultipartFile file) throws IOException {
|
public static final String upload(MultipartFile file) throws IOException {
|
||||||
try {
|
try {
|
||||||
FileUtils.assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
FileUtils.assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||||
return fileUtil.upload(file);
|
return fileService.upload(file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException(e.getMessage(), 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 {
|
public static final String upload(String filePath, MultipartFile file, String[] allowedExtension) throws Exception {
|
||||||
FileUtils.assertAllowed(file, allowedExtension);
|
FileUtils.assertAllowed(file, allowedExtension);
|
||||||
return fileUtil.upload(filePath, file);
|
return fileService.upload(filePath, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +86,7 @@ public class FileOperateUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static final void downLoad(String fileUrl, OutputStream outputStream) throws Exception {
|
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);
|
FileUtils.writeBytes(inputStream, outputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,6 +98,6 @@ public class FileOperateUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static final boolean deleteFile(String fileUrl) throws Exception {
|
public static final boolean deleteFile(String fileUrl) throws Exception {
|
||||||
return fileUtil.deleteFile(fileUrl);
|
return fileService.deleteFile(fileUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import java.io.InputStream;
|
|||||||
/**
|
/**
|
||||||
* 文件操作接口
|
* 文件操作接口
|
||||||
*/
|
*/
|
||||||
public interface FileUtil {
|
public interface FileService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
@ -18,7 +18,7 @@ public interface FileUtil {
|
|||||||
* @param file 文件对象
|
* @param file 文件对象
|
||||||
* @return 返回上传成功的文路径
|
* @return 返回上传成功的文路径
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String upload(String filePath, MultipartFile file) throws Exception;
|
public String upload(String filePath, MultipartFile file) throws Exception;
|
||||||
|
|
||||||
@ -29,17 +29,17 @@ public interface FileUtil {
|
|||||||
* @param file 文件对象
|
* @param file 文件对象
|
||||||
* @return 返回上传成功的文路径
|
* @return 返回上传成功的文路径
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String upload(MultipartFile file, String name) throws Exception;
|
public String upload(MultipartFile file, String name) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传
|
* 文件上传
|
||||||
*
|
*
|
||||||
* @param file 文件对象
|
* @param file 文件对象
|
||||||
* @return 返回上传成功的文路径
|
* @return 返回上传成功的文路径
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String upload(MultipartFile file) throws Exception;
|
public String upload(MultipartFile file) throws Exception;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public interface FileUtil {
|
|||||||
* @param file 文件对象
|
* @param file 文件对象
|
||||||
* @return 返回上传成功的文路径
|
* @return 返回上传成功的文路径
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String upload(String baseDir, String fileName, MultipartFile file) throws Exception;
|
public String upload(String baseDir, String fileName, MultipartFile file) throws Exception;
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ public interface FileUtil {
|
|||||||
* @param filePath 下载的文件路径
|
* @param filePath 下载的文件路径
|
||||||
* @return 返回上传成功的文路径
|
* @return 返回上传成功的文路径
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public InputStream downLoad(String filePath) throws Exception;
|
public InputStream downLoad(String filePath) throws Exception;
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ public interface FileUtil {
|
|||||||
* @param filePath 删除的文件路径
|
* @param filePath 删除的文件路径
|
||||||
* @return 返回上传成功的文路径
|
* @return 返回上传成功的文路径
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public boolean deleteFile(String filePath) throws Exception;
|
public boolean deleteFile(String filePath) throws Exception;
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package com.ruoyi.middleware.minio.utils;
|
package com.ruoyi.middleware.minio.utils;
|
||||||
|
|
||||||
import com.ruoyi.common.config.RuoYiConfig;
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
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.file.FileUtils;
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
import com.ruoyi.middleware.minio.config.MinioConfig;
|
import com.ruoyi.middleware.minio.config.MinioConfig;
|
||||||
@ -18,7 +17,7 @@ import java.io.InputStream;
|
|||||||
* Minio文件操作实现类
|
* Minio文件操作实现类
|
||||||
*/
|
*/
|
||||||
@Component("file:strategy:minio")
|
@Component("file:strategy:minio")
|
||||||
public class MinioFileUtil implements FileUtil {
|
public class MinioFileService implements FileService {
|
||||||
private static MinioConfig minioConfig = SpringUtils.getBean(MinioConfig.class);
|
private static MinioConfig minioConfig = SpringUtils.getBean(MinioConfig.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
Loading…
Reference in New Issue
Block a user