parent
e1e05b761a
commit
532f202b8c
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.file.config;
|
package com.ruoyi.file.config;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
|
|
@ -8,8 +9,9 @@ import io.minio.MinioClient;
|
||||||
/**
|
/**
|
||||||
* Minio 配置信息
|
* Minio 配置信息
|
||||||
*
|
*
|
||||||
* @author ruoiy
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@RefreshScope
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = "minio")
|
@ConfigurationProperties(prefix = "minio")
|
||||||
public class MinioConfig
|
public class MinioConfig
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.file.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
@ -11,6 +12,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@RefreshScope
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ResourcesConfig implements WebMvcConfigurer
|
public class ResourcesConfig implements WebMvcConfigurer
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.file.service;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
||||||
|
|
@ -13,6 +14,7 @@ import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@RefreshScope
|
||||||
@Service
|
@Service
|
||||||
public class FastDfsSysFileServiceImpl implements ISysFileService
|
public class FastDfsSysFileServiceImpl implements ISysFileService
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.ruoyi.file.service;
|
package com.ruoyi.file.service;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
@ -12,6 +13,7 @@ import com.ruoyi.file.utils.FileUploadUtils;
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Primary
|
@Primary
|
||||||
|
@RefreshScope
|
||||||
@Service
|
@Service
|
||||||
public class LocalSysFileServiceImpl implements ISysFileService
|
public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
{
|
{
|
||||||
|
|
@ -40,6 +42,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
* @return 访问地址
|
* @return 访问地址
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
String name = FileUploadUtils.upload(localFilePath, file);
|
String name = FileUploadUtils.upload(localFilePath, file);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
* @return 访问地址
|
* @return 访问地址
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
String fileName = FileUploadUtils.extractFilename(file);
|
String fileName = FileUploadUtils.extractFilename(file);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.ruoyi.file.utils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.ruoyi.common.core.exception.file.FileNameLengthLimitExceededException;
|
import com.ruoyi.common.core.exception.file.FileNameLengthLimitExceededException;
|
||||||
import com.ruoyi.common.core.exception.file.FileSizeLimitExceededException;
|
import com.ruoyi.common.core.exception.file.FileSizeLimitExceededException;
|
||||||
|
|
@ -17,6 +18,7 @@ import com.ruoyi.common.core.utils.file.MimeTypeUtils;
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@RefreshScope
|
||||||
public class FileUploadUtils
|
public class FileUploadUtils
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,7 +56,7 @@ public class FileUploadUtils
|
||||||
*
|
*
|
||||||
* @param baseDir 相对应用的基目录
|
* @param baseDir 相对应用的基目录
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @param extension 上传文件类型
|
* @param allowedExtension 上传文件类型
|
||||||
* @return 返回上传成功的文件名
|
* @return 返回上传成功的文件名
|
||||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||||
* @throws FileNameLengthLimitExceededException 文件名太长
|
* @throws FileNameLengthLimitExceededException 文件名太长
|
||||||
|
|
@ -116,9 +118,8 @@ public class FileUploadUtils
|
||||||
* 文件大小校验
|
* 文件大小校验
|
||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @return
|
|
||||||
* @throws FileSizeLimitExceededException 如果超出最大大小
|
* @throws FileSizeLimitExceededException 如果超出最大大小
|
||||||
* @throws InvalidExtensionException
|
* @throws InvalidExtensionException 文件校验异常
|
||||||
*/
|
*/
|
||||||
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
|
public static final void assertAllowed(MultipartFile file, String[] allowedExtension)
|
||||||
throws FileSizeLimitExceededException, InvalidExtensionException
|
throws FileSizeLimitExceededException, InvalidExtensionException
|
||||||
|
|
@ -163,9 +164,9 @@ public class FileUploadUtils
|
||||||
/**
|
/**
|
||||||
* 判断MIME类型是否是允许的MIME类型
|
* 判断MIME类型是否是允许的MIME类型
|
||||||
*
|
*
|
||||||
* @param extension
|
* @param extension 上传文件类型
|
||||||
* @param allowedExtension
|
* @param allowedExtension 允许上传文件类型
|
||||||
* @return
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public static final boolean isAllowedExtension(String extension, String[] allowedExtension)
|
public static final boolean isAllowedExtension(String extension, String[] allowedExtension)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue