1、DfsService积累 新增删除、获取磁盘空间(总空间、可用空间)方法
2、本地文件LocalFile 实现完毕 & 测试通过
This commit is contained in:
parent
fb028d7091
commit
d832c1a2f7
|
|
@ -40,33 +40,40 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- FastDFS -->
|
||||
|
||||
<!-- 解决 使用了 【ConfigurationProperties】出现 Spring Boot Configuration Annotation Processor not configured 提示问题 -->
|
||||
<dependency>
|
||||
<groupId>com.github.tobato</groupId>
|
||||
<artifactId>fastdfs-client</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Minio -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>${minio.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- RuoYi Api System -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-api-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- RuoYi Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- apache commons net ftp工具类; hutool 里面 scope 是 compile -->
|
||||
<!-- 文件服务器1:FastDFS -->
|
||||
<dependency>
|
||||
<groupId>com.github.tobato</groupId>
|
||||
<artifactId>fastdfs-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 文件服务器2:Minio -->
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>${minio.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 文件服务器3:apache commons net ftp工具类; hutool 里面 scope 是 compile -->
|
||||
<!--用来ftp上传-->
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
|
|
@ -79,7 +86,7 @@
|
|||
<version>5.7.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--阿里云OSS库-->
|
||||
<!-- 文件服务器4:阿里云OSS库-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
|
|
@ -105,7 +112,7 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!--ceph upload start -->
|
||||
<!-- 文件服务器5:ceph upload start -->
|
||||
<!--文件上传 ceph 形式,一般项目都用不上,注释掉; 不要删-->
|
||||
<!-- ceph实现s3 文件上传-->
|
||||
<dependency>
|
||||
|
|
@ -120,7 +127,7 @@
|
|||
</dependency>
|
||||
<!--ceph upload end -->
|
||||
|
||||
<!--七牛云文件存储 start -->
|
||||
<!--文件服务器6:七牛云文件存储 start -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
|
|
@ -142,6 +149,15 @@
|
|||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<!-- 打包的时候,相关的包不打入依赖-->
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,28 @@
|
|||
package com.ruoyi.file;
|
||||
|
||||
import com.ruoyi.file.config.*;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
||||
/**
|
||||
* 文件服务
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@EnableConfigurationProperties(value = {
|
||||
LocalFileConfig.class,
|
||||
FtpConfig.class,
|
||||
FastDfsConfig.class,
|
||||
AliyunOssConfig.class,
|
||||
CephConfig.class,
|
||||
MinioConfig.class,
|
||||
QiniuKodoConfig.class,
|
||||
ServerProperties.class
|
||||
})
|
||||
@EnableCustomSwagger2
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
|
||||
public class RuoYiFileApplication
|
||||
|
|
|
|||
|
|
@ -14,8 +14,9 @@ import org.springframework.context.annotation.Configuration;
|
|||
*/
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "aliyunoss")
|
||||
@ConfigurationProperties(prefix = AliyunOssConfig.PREFIX)
|
||||
public class AliyunOssConfig {
|
||||
public static final String PREFIX = "aliyun-oss";
|
||||
/**
|
||||
* aliyun oss相关配置
|
||||
* ACCESS_KEY_SECRET
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ import org.springframework.context.annotation.Configuration;
|
|||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(
|
||||
prefix = "ceph"
|
||||
prefix = CephConfig.PREFIX
|
||||
)
|
||||
public class CephConfig {
|
||||
public static final String PREFIX = "ceph";
|
||||
/**
|
||||
* s3 提供的 accessKey secretKey
|
||||
* 示例:
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ import org.springframework.context.annotation.Configuration;
|
|||
@ConfigurationProperties(
|
||||
prefix = FdfsClientConstants.ROOT_CONFIG_PREFIX
|
||||
)
|
||||
public class FastDfsConfig extends PooledConnectionFactory {
|
||||
public class FastDfsConfig {
|
||||
/**
|
||||
* 域名或本机访问地址
|
||||
* 文件对外访问域名or ip
|
||||
* FastDFS配置 其他参数见:{@link PooledConnectionFactory}
|
||||
* //@Value("${fdfs.domain}")
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.file.config;
|
||||
|
||||
import com.ruoyi.file.service.FtpFileServiceImpl;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -9,13 +10,15 @@ import org.springframework.context.annotation.Configuration;
|
|||
* vsftpd 服务器搭建、ftp客户端filezilla使、ceph分布式文件系统
|
||||
* https://blog.csdn.net/ab601026460/article/details/105928311
|
||||
* @author dazer
|
||||
* @see FtpFileServiceImpl
|
||||
*/
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(
|
||||
prefix = "ftp"
|
||||
prefix = FtpConfig.PREFIX
|
||||
)
|
||||
public class FtpConfig {
|
||||
public static final String PREFIX = "ftp";
|
||||
/**
|
||||
* ftp访问地址
|
||||
* eg1: www.ourslook.com
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package com.ruoyi.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import com.ruoyi.file.service.LocalFileServiceImpl;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -11,48 +12,55 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||
/**
|
||||
* 本地文件配置
|
||||
* 通用映射配置
|
||||
*
|
||||
* @see LocalFileServiceImpl
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
public class LocalConfig implements WebMvcConfigurer
|
||||
@ConfigurationProperties(prefix = LocalFileConfig.PREFIX)
|
||||
public class LocalFileConfig implements WebMvcConfigurer
|
||||
{
|
||||
public static final String PREFIX = "file";
|
||||
/**
|
||||
* 文件对外访问地址,一般就是应用 或者 nginx对外地址
|
||||
* eg: http://127.0.0.1:9300
|
||||
* ///@Value("${file.domain}")
|
||||
*/
|
||||
private String domain;
|
||||
|
||||
/**
|
||||
* 资源映射路径 前缀
|
||||
* eg: eg: /statics
|
||||
* 一般访问:${domain}/${prefix}/key
|
||||
* ///@Value("${file.prefix}")
|
||||
*
|
||||
* 上传之后的路径,形如:"url": "http://localhost:9300/statics/2021/07/16/25292b96-a107-4cf8-baca-e1cb693fd078.jpg"
|
||||
*/
|
||||
@Value("${file.prefix}")
|
||||
private String localFilePrefix;
|
||||
|
||||
/**
|
||||
* 域名或本机访问地址
|
||||
* eg: http://127.0.0.1:9300
|
||||
*/
|
||||
@Value("${file.domain}")
|
||||
private String domain;
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* 上传文件存储在本地的根路径
|
||||
* eg: D:/ruoyi/uploadPath
|
||||
* ///@Value("${file.path}")
|
||||
*/
|
||||
@Value("${file.path}")
|
||||
private String localFilePath;
|
||||
private String path;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry)
|
||||
{
|
||||
/** 本地文件上传路径 */
|
||||
registry.addResourceHandler(localFilePrefix + "/**")
|
||||
.addResourceLocations("file:" + localFilePath + File.separator);
|
||||
registry.addResourceHandler(prefix + "/**")
|
||||
.addResourceLocations("file:" + path + File.separator);
|
||||
}
|
||||
|
||||
public String getLocalFilePrefix() {
|
||||
return localFilePrefix;
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setLocalFilePrefix(String localFilePrefix) {
|
||||
this.localFilePrefix = localFilePrefix;
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
|
|
@ -63,11 +71,11 @@ public class LocalConfig implements WebMvcConfigurer
|
|||
this.domain = domain;
|
||||
}
|
||||
|
||||
public String getLocalFilePath() {
|
||||
return localFilePath;
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setLocalFilePath(String localFilePath) {
|
||||
this.localFilePath = localFilePath;
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,25 @@
|
|||
package com.ruoyi.file.config;
|
||||
|
||||
import com.ruoyi.file.service.MinioDfsServiceImpl;
|
||||
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.Configuration;
|
||||
import io.minio.MinioClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Minio 配置信息
|
||||
*
|
||||
* @author ruoyi
|
||||
* @see MinioDfsServiceImpl 实现
|
||||
*/
|
||||
@RefreshScope
|
||||
@Component
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "minio")
|
||||
public class MinioConfig
|
||||
{
|
||||
@ConfigurationProperties(prefix = MinioConfig.PREFIX)
|
||||
public class MinioConfig {
|
||||
public static final String PREFIX = "minio";
|
||||
/**
|
||||
* 服务地址
|
||||
* eg: http://192.168.254.100:9900
|
||||
|
|
@ -40,49 +44,40 @@ public class MinioConfig
|
|||
*/
|
||||
private String bucketName;
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url)
|
||||
{
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getAccessKey()
|
||||
{
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey)
|
||||
{
|
||||
public void setAccessKey(String accessKey) {
|
||||
this.accessKey = accessKey;
|
||||
}
|
||||
|
||||
public String getSecretKey()
|
||||
{
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey)
|
||||
{
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public String getBucketName()
|
||||
{
|
||||
public String getBucketName() {
|
||||
return bucketName;
|
||||
}
|
||||
|
||||
public void setBucketName(String bucketName)
|
||||
{
|
||||
public void setBucketName(String bucketName) {
|
||||
this.bucketName = bucketName;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MinioClient getMinioClient()
|
||||
{
|
||||
public MinioClient getMinioClient() {
|
||||
return MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ import org.springframework.context.annotation.Configuration;
|
|||
*/
|
||||
@RefreshScope
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "qiniu")
|
||||
@ConfigurationProperties(prefix = QiniuKodoConfig.PREFIX)
|
||||
public class QiniuKodoConfig {
|
||||
public static final String PREFIX = "qiniu";
|
||||
/**
|
||||
* AccessKey 简称ak
|
||||
* 申请地址=>登录七牛云:https://portal.qiniu.com/user/key
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.ruoyi.file.controller;
|
||||
|
||||
import com.ruoyi.file.service.IDfsService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -13,36 +15,58 @@ import com.ruoyi.system.api.domain.SysFile;
|
|||
|
||||
/**
|
||||
* 文件请求处理
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
public class SysFileController
|
||||
{
|
||||
public class SysFileController {
|
||||
private static final Logger log = LoggerFactory.getLogger(SysFileController.class);
|
||||
|
||||
@Autowired
|
||||
private IDfsService sysFileService;
|
||||
private IDfsService dfsService;
|
||||
|
||||
/**
|
||||
* 文件上传请求
|
||||
*/
|
||||
@PostMapping("upload")
|
||||
public R<SysFile> upload(MultipartFile file)
|
||||
{
|
||||
try
|
||||
{
|
||||
public R<SysFile> upload(MultipartFile file) {
|
||||
try {
|
||||
// 上传并返回访问地址
|
||||
String url = sysFileService.uploadFile(file);
|
||||
String url = dfsService.uploadFile(file);
|
||||
SysFile sysFile = new SysFile();
|
||||
sysFile.setName(FileUtils.getName(url));
|
||||
sysFile.setUrl(url);
|
||||
return R.ok(sysFile);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
log.error("上传文件失败", e);
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
@PostMapping("delete")
|
||||
public R<Boolean> delete(String fileUrl) {
|
||||
if (StringUtils.isBlank(fileUrl)) {
|
||||
return R.fail(false, "fileUrl 不能为空");
|
||||
}
|
||||
try {
|
||||
// 上传并返回访问地址
|
||||
boolean isOk = dfsService.deleteFile(fileUrl);
|
||||
return isOk ? R.ok(true, "删除成功") : R.fail(false, "删除失败");
|
||||
} catch (Exception e) {
|
||||
log.error("删除文件失败", e);
|
||||
return R.fail(false, "删除失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件总大小,占用内容大小;
|
||||
* 形如:总 233.57 GB, 可用 72.12 GB
|
||||
*/
|
||||
@GetMapping("objectsCapacityStr")
|
||||
public R<String> objectsCapacityStr() {
|
||||
return R.ok(dfsService.objectsCapacityStr(), "获取成功");
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ import java.io.IOException;
|
|||
* @author dazer
|
||||
*/
|
||||
@Service
|
||||
public class FtpDfsServiceImpl implements IDfsService {
|
||||
public class FtpFileServiceImpl implements IDfsService {
|
||||
@Autowired
|
||||
private FtpConfig ftpConfig;
|
||||
public static final String ACCESS_PREFIX = "";
|
||||
|
|
@ -60,7 +60,7 @@ public interface IDfsService
|
|||
/**
|
||||
* 获取文件占用空间
|
||||
* 别名:objectsCapacity
|
||||
* @return 文件大小字符串,eg: 100MB、2G
|
||||
* @return 文件大小字符串,eg: 100MB、2G; 形如:总 233.57 GB, 可用 72.12 GB
|
||||
*/
|
||||
String objectsCapacityStr();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
package com.ruoyi.file.service;
|
||||
|
||||
import com.ruoyi.common.core.exception.CustomException;
|
||||
import com.ruoyi.file.config.LocalConfig;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.file.utils.FileUploadUtils;
|
||||
|
||||
/**
|
||||
* 本地文件存储
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
public class LocalDfsServiceImpl implements IDfsService
|
||||
{
|
||||
private final LocalConfig localConfig;
|
||||
|
||||
public LocalDfsServiceImpl(LocalConfig localConfig) {
|
||||
this.localConfig = localConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地文件上传接口
|
||||
*
|
||||
* @param file 上传的文件
|
||||
* @return 访问地址
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file) throws Exception
|
||||
{
|
||||
return this.uploadFile(file, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file, String modules) throws Exception {
|
||||
String localFilePath = localConfig.getLocalFilePath();
|
||||
String domain = localConfig.getDomain();
|
||||
String localFilePrefix = localConfig.getLocalFilePrefix();
|
||||
|
||||
String name = FileUploadUtils.upload(localFilePath + "/" + StringUtils.defaultString(modules, ""), file);
|
||||
return domain + localFilePrefix + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFile(String fileUrl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String objectsCapacityStr() {
|
||||
throw new CustomException("本地存储-获取文件占用空间功能,敬请期待");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
package com.ruoyi.file.service;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.ruoyi.common.core.exception.CustomException;
|
||||
import com.ruoyi.file.config.LocalFileConfig;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.file.utils.FileUploadUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 本地文件存储
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
public class LocalFileServiceImpl implements IDfsService
|
||||
{
|
||||
private final LocalFileConfig localFileConfig;
|
||||
|
||||
public LocalFileServiceImpl(LocalFileConfig localFileConfig) {
|
||||
this.localFileConfig = localFileConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地文件上传接口
|
||||
*
|
||||
* @param file 上传的文件
|
||||
* @return 访问地址
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file) throws Exception
|
||||
{
|
||||
return this.uploadFile(file, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFile(MultipartFile file, String modules) throws Exception {
|
||||
String localFilePath = localFileConfig.getPath();
|
||||
String domain = localFileConfig.getDomain();
|
||||
String localFilePrefix = localFileConfig.getPrefix();
|
||||
if (StringUtils.isBlank(localFilePath) ||
|
||||
StringUtils.isBlank(localFilePath) ||
|
||||
StringUtils.isBlank(localFilePath) ) {
|
||||
throw new CustomException("文件服务器:file 相关配置不能为空!");
|
||||
}
|
||||
|
||||
String name = FileUploadUtils.upload(localFilePath + "/" + StringUtils.defaultString(modules, ""), file);
|
||||
return domain + localFilePrefix + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFile(String fileUrl) {
|
||||
if (StringUtils.isBlank(fileUrl)) {
|
||||
throw new CustomException("fileUrl不能为空!");
|
||||
}
|
||||
String key = this.getStorePath(fileUrl);
|
||||
String localFilePath = localFileConfig.getPath();
|
||||
|
||||
String filePath = localFilePath + "/" + key;
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
throw new CustomException("文件不存在,或者已经删除:" + filePath);
|
||||
}
|
||||
try {
|
||||
return file.delete();
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("文件删除失败:" + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String objectsCapacityStr() {
|
||||
String localFilePath = localFileConfig.getPath();
|
||||
File file = new File(localFilePath);
|
||||
long total = file.getTotalSpace();
|
||||
long free = file.getFreeSpace();
|
||||
String totalSpace = FileUtil.readableFileSize(total);
|
||||
String freeSpace = FileUtil.readableFileSize(free);
|
||||
return "总 " + totalSpace + ", 可用 " + freeSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换url,为原始的key
|
||||
*
|
||||
* @param filePath http://localhost:9300/statics/2021/07/16/25292b96-a107-4cf8-baca-e1cb693fd078.jpg
|
||||
* @return 2021/07/16/25292b96-a107-4cf8-baca-e1cb693fd078.jpg
|
||||
*/
|
||||
private String getStorePath(String filePath) {
|
||||
// 使用方式1
|
||||
String domain = localFileConfig.getDomain();
|
||||
String localFilePrefix = localFileConfig.getPrefix();
|
||||
String publicPath1 = domain + localFilePrefix;
|
||||
String key = filePath.replace(publicPath1, "");
|
||||
|
||||
if (key.equals(filePath)) {
|
||||
// 使用方式2
|
||||
String group = localFileConfig.getPrefix();
|
||||
// 获取group起始位置
|
||||
int pathStartPos = filePath.indexOf(group) + group.length() + 1;
|
||||
key = filePath.substring(pathStartPos, filePath.length());
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ public class QiniuDfsServiceImpl implements IDfsService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 转换url
|
||||
* 转换url,为原始的key
|
||||
*
|
||||
* @param filePath http://guangdong-oss.ityun.ltd/upload/default/header.jpg
|
||||
* @return upload/default/header.jpg
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ spring:
|
|||
application:
|
||||
# 应用名称
|
||||
name: ruoyi-file
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
|
|
@ -23,3 +25,26 @@ spring:
|
|||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
|
||||
# 文件服务器之1 本地文件上传
|
||||
file:
|
||||
domain: http://localhost:9300
|
||||
prefix: /statics
|
||||
path: D:/ruoyi/uploadPath
|
||||
|
||||
# 文件服务器之3 FastDFS配置
|
||||
fdfs:
|
||||
domain: http://8.129.231.12
|
||||
soTimeout: 3000
|
||||
connectTimeout: 2000
|
||||
trackerList: 8.129.231.12:22122
|
||||
|
||||
# 文件服务器之4 Minio配置
|
||||
minio:
|
||||
url: http://192.168.254.100:9900
|
||||
accessKey: D99KGE6ZTQXSATTJWU24
|
||||
secretKey: QyVqGnhIQQE734UYSUFlGOZViE6+ZlDEfUG3NjhJ
|
||||
bucketName: neusoft-appt
|
||||
#regex: .*appt-file/
|
||||
#encryptFlag: true
|
||||
|
|
|
|||
Loading…
Reference in New Issue