From 407b7e526ff7f3dee15054e549284023caf22f75 Mon Sep 17 00:00:00 2001 From: duandazhi Date: Fri, 23 Jul 2021 17:19:28 +0800 Subject: [PATCH] =?UTF-8?q?fastdfs=20fix=20upload=20bug=E3=80=81=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E5=B0=8F=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/ruoyi/file/config/FastDfsConfig.java | 2 ++ .../com/ruoyi/file/service/FastDfsServiceImpl.java | 12 ++++++++++-- .../ruoyi-file/src/main/resources/bootstrap.yml | 11 ++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 4d55708a..4988ff9f 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 2.1.4 3.0.0 1.6.2 - 1.26.5 + 1.26.7 2.3.2 1.3.1 1.2.6 diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/FastDfsConfig.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/FastDfsConfig.java index dd65f0b6..9ddf178b 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/FastDfsConfig.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/FastDfsConfig.java @@ -12,6 +12,8 @@ import org.springframework.context.annotation.Configuration; * @author dazer * @see FastDfsServiceImpl * FastDFS配置 其他参数见:{@link PooledConnectionFactory} + * + * 使用: Docker部署FastDFS(附示例代码) https://www.cnblogs.com/cao-lei/p/13470695.html */ @RefreshScope @Configuration diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsServiceImpl.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsServiceImpl.java index e2bd1845..c5052ed4 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsServiceImpl.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsServiceImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.file.service; +import com.github.tobato.fastdfs.domain.fdfs.MetaData; import com.github.tobato.fastdfs.exception.FdfsUnsupportStorePathException; import com.ruoyi.common.core.exception.CustomException; import com.ruoyi.file.config.FastDfsConfig; @@ -8,11 +9,15 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import com.github.tobato.fastdfs.domain.fdfs.StorePath; import com.github.tobato.fastdfs.service.FastFileStorageClient; +import java.util.HashSet; +import java.util.Set; + /** * FastDFS 文件存储 * @author ruoyi @@ -38,7 +43,7 @@ public class FastDfsServiceImpl implements IDfsService @Override public String uploadFile(MultipartFile file) throws Exception { - return this.uploadFile(file); + return this.uploadFile(file, null); } @Override @@ -46,8 +51,11 @@ public class FastDfsServiceImpl implements IDfsService // fastdsf 这里的 modules 没用 validateModule(file, modules); + Set metaDataSet = new HashSet<>(1); + metaDataSet.add(new MetaData("groupName", "group1")); + StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), - FilenameUtils.getExtension(file.getOriginalFilename()), null); + FilenameUtils.getExtension(file.getOriginalFilename()), metaDataSet); /// fileUrl = "http://127.0.0.1:22122/" + storePath.getFullPath(); return fastDfsConfig.getDomain() + "/" + storePath.getFullPath(); diff --git a/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml index 4b439b6e..5bd0f15c 100644 --- a/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml @@ -17,11 +17,9 @@ spring: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 - namespace: 72b686a1-d9f6-499f-8275-e481b664779e config: # 配置中心地址 server-addr: 127.0.0.1:8848 - namespace: 72b686a1-d9f6-499f-8275-e481b664779e # 配置文件格式 file-extension: yml # 共享配置 @@ -37,7 +35,7 @@ file: # 文件服务器之2 ftp ftp: - host-name: 118.31.2.53 + endpoint: 118.31.2.53 port: 21 user-name: lanjinjun password: @@ -57,14 +55,16 @@ minio: secretKey: QyVqGnhIQQE734UYSUFlGOZViE6+ZlDEfUG3NjhJ bucketName: appt-file domain: https://yq666.bj.gov.cn + expiry-duration: 32400 # 文件服务器之5 aliyun oss aliyun-oss: - access-key-id: LTAI4GDQSbwgmbsRxxbDXnKT - access-key-secret: I1xYosCsIf4YgHeFbWUOU4faImeWD2 + access-key: LTAI4GDQSbwgmbsRxxbDXnKT + secret-key: I1xYosCsIf4YgHeFbWUOU4faImeWD2 bucket-name: react-yuebaoxiao-pro endpoint: oss-cn-shanghai.aliyuncs.com domain: https://react-yuebaoxiao-pro.oss-cn-shanghai.aliyuncs.com + expiry-duration: 32400 # 文件服务器之6 qiniu 七牛 kodo qiniu: @@ -72,3 +72,4 @@ qiniu: secret-key: CwTEh1kSLBdxBhIWfFz6h1GgDSokx97CYEV0cC1O bucket-name: guangdong-oss domain: http://guangdong-oss.ityun.ltd + expiry-duration: 32400