From 9afeb3e4b43deb841679c7ef9ea2029d21569889 Mon Sep 17 00:00:00 2001 From: wangzhijiang <1358525938@qq.com> Date: Tue, 4 Jun 2024 10:55:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=8B=86=E5=88=86=EF=BC=8C?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?local?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oss/service/impl/OSSFileServiceImpl.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/byd-structuredplugins-serve/laws-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java b/byd-structuredplugins-serve/laws-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java index a274c7d..5d8b98d 100644 --- a/byd-structuredplugins-serve/laws-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java +++ b/byd-structuredplugins-serve/laws-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java @@ -3,6 +3,7 @@ package com.jero.modules.oss.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.jero.common.constant.CommonConstant; import com.jero.common.constant.enums.LanguageEnum; import com.jero.common.exception.JeroBootException; import com.jero.common.system.vo.LoginUser; @@ -35,6 +36,11 @@ public class OSSFileServiceImpl extends ServiceImpl impl private String uploadpath; @Value(value = "${jero.path.uploadCos}") private String uploadCospath; + /** + * 本地:local minio:minio 阿里:alioss + */ + @Value(value = "${jero.uploadType}") + private String uploadType; /** * 文件后缀黑名单 */ @@ -174,21 +180,30 @@ public class OSSFileServiceImpl extends ServiceImpl impl // 将文件上传至腾讯云 cos - String upload = MinioUtil.upload(mf, "/" + uploadCospath); +// String aa = MinioUtil.upload(mf, "/" + uploadCospath); + String upload = ""; + if (CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)) { + // 本地上传 + upload = CommonUtils.uploadLocal(mf, bizPath, uploadpath); + } else { + // minio上传 + upload = CommonUtils.upload(mf, bizPath, uploadType); + } // LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String userId = ""; //存入文件表 oSSFile.setFileName(orgName); oSSFile.setId(UuidUtils.getUUID()); + oSSFile.setUrl(upload); oSSFile.setCreateBy(userId); oSSFile.setCreateTime(new Date()); this.save(oSSFile); // 文件路径做特殊处理 // BASE64Encoder base64Encoder = new BASE64Encoder(); // String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8)); - String imgUrl = upload.split("/")[1]; - oSSFile.setUrl(splitUrl + imgUrl); +// String imgUrl = upload.split("/")[1]; + oSSFile.setUrl(splitUrl + oSSFile.getId()); return oSSFile; }