Minio配置、aliyun oss、qiuniu kado 文件加签访问 测试完成,没有问题
This commit is contained in:
parent
69dc496580
commit
f412996375
|
|
@ -7,6 +7,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
/**
|
||||
* aliyun oss https://help.aliyun.com/learn/learningpath/oss.html ,需要购买
|
||||
* 使用STS临时访问凭证访问OSS https://help.aliyun.com/document_detail/100624.html?spm=5176.8466032.help.dexternal.5ded1450am61oS
|
||||
*
|
||||
* @author dazer
|
||||
*
|
||||
|
|
@ -52,6 +53,11 @@ public class AliyunOssConfig {
|
|||
* 如:-1: 就永不过期,原样返回url
|
||||
* 签名URL的默认过期时间为3600秒,最大值为32400秒
|
||||
* 文档:对象存储 授权访问 https://help.aliyun.com/document_detail/32016.html?spm=a2c4g.11186623.6.996.335b6d13O5xgUH
|
||||
*
|
||||
* 注意!!:aliyun oss 设置Bucket ACL: bucket==>权限管理==>读写权限
|
||||
* 1、私有 【必须要加签之后才能访问】
|
||||
* 2、公共读
|
||||
* 3、公共读写
|
||||
*/
|
||||
private Long expiryDuration = 32400L;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import org.springframework.context.annotation.Configuration;
|
|||
import io.minio.MinioClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Minio 配置信息
|
||||
|
|
@ -55,6 +54,12 @@ public class MinioConfig {
|
|||
/**
|
||||
* 访问域名; url经常是内网地址,外部访问用域名或者外网ip
|
||||
* eg: https://yq666.bj.gov.cn/appt-file
|
||||
*
|
||||
* 注意!!:minio要配置 Bucket Policy: Bucket ==> Edit Bucket
|
||||
* 1、Read Only
|
||||
* 2、Write Only
|
||||
* 3、Read and Write
|
||||
* 4、不做任何分配 【必须要加签之后才能访问】
|
||||
*/
|
||||
private String domain;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,18 @@ public class QiniuKodoConfig {
|
|||
private String secretKey;
|
||||
private String bucketName;
|
||||
private String domain;
|
||||
/**
|
||||
* 过期时间,单位秒;
|
||||
* 如:1小时就写:3600L
|
||||
* 如:9小时就写:32400L
|
||||
* 如:12小时就写:43200L, 【不支持】,最大是 未知, 最小 1(1秒钟)
|
||||
* 如:-1: 就永不过期,原样返回url
|
||||
* 签名URL的默认过期时间为3600秒,最大值为32400秒
|
||||
*
|
||||
* 注意!!:qoniu oss 设置Bucket私有,必须要有凭证才能访问 https://developer.qiniu.com/kodo/1202/download-token
|
||||
* 下载凭证(如果Bucket设置成私有,必须要有 下载凭证),路径:【对象存储==》使用指南===》安全机制===》 下载凭证】
|
||||
*/
|
||||
private Long expiryDuration = 32400L;
|
||||
|
||||
public String getAccessKey() {
|
||||
return accessKey;
|
||||
|
|
@ -71,4 +83,16 @@ public class QiniuKodoConfig {
|
|||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public Long getExpiryDuration() {
|
||||
if (expiryDuration != -1 && expiryDuration < 0) {
|
||||
// 最小是1秒
|
||||
expiryDuration = 1L;
|
||||
}
|
||||
return expiryDuration;
|
||||
}
|
||||
|
||||
public void setExpiryDuration(Long expiryDuration) {
|
||||
this.expiryDuration = expiryDuration;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ 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;
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* //@see AliyunMsgUtil
|
||||
*/
|
||||
//@Primary
|
||||
@Service
|
||||
@Service()
|
||||
public class AliyunOssDsfServiceImpl implements IDfsService {
|
||||
private static final Logger log = LoggerFactory.getLogger(AliyunOssDsfServiceImpl.class);
|
||||
@Autowired
|
||||
|
|
@ -516,6 +517,10 @@ public class AliyunOssDsfServiceImpl implements IDfsService {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileUrl https://react-yuebaoxiao-pro.oss-cn-shanghai.aliyuncs.com/dev/upload/default/20210722-03f07351-ae82-410a-a43c-0797a82f07b4.jpeg
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String presignedUrl(String fileUrl) {
|
||||
if (aliyunOssConfig.getExpiryDuration() == -1) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import javax.annotation.PostConstruct;
|
|||
* 2:ceph存储,使用docker部署 https://www.cnblogs.com/bladeyul/p/10649049.html
|
||||
* 3:使用docker 搭建 ceph 开发环境,使用aws sdk 存储数据 https://blog.csdn.net/freewebsys/article/details/79553386
|
||||
*/
|
||||
@Service
|
||||
@Service()
|
||||
public class CephDfsServiceImpl implements IDfsService {
|
||||
private static final Logger log = LoggerFactory.getLogger(CephDfsServiceImpl.class);
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
|||
* @author ruoyi
|
||||
* @see FastDfsConfig
|
||||
*/
|
||||
@Service
|
||||
@Service()
|
||||
public class FastDfsServiceImpl implements IDfsService
|
||||
{
|
||||
private final Logger logger = LoggerFactory.getLogger(FastDfsServiceImpl.class);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import java.io.IOException;
|
|||
* ftp, 如:iis、linux ftp、vsftpd、FileZilla Server,需要自己搭建服务
|
||||
* @author dazer
|
||||
*/
|
||||
@Service
|
||||
@Service()
|
||||
public class FtpFileServiceImpl implements IDfsService {
|
||||
@Autowired
|
||||
private FtpConfig ftpConfig;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public interface IDfsService
|
|||
* 2、minio 叫做;resignedGetObject 临时安全令牌(Security Token Service,STS); 【Presigned presignedGetObject 预签】
|
||||
* http://docs.minio.org.cn/docs/master/minio-sts-quickstart-guide
|
||||
* minio SDKS Java Client API参考文档 http://docs.minio.org.cn/docs/master/java-client-api-reference
|
||||
* 3、qiniu ;七牛云存储; 构建时间戳防盗链访问链接: https://developer.qiniu.com/kodo/1239/java#fusion-antileech
|
||||
* 3、qiniu ;七牛云存储; 下载凭证(如果Bucket设置成私有,必须要有 下载凭证),路径:【对象存储==》使用指南===》安全机制===》 下载凭证】 https://developer.qiniu.com/kodo/1202/download-token
|
||||
* https://developer.qiniu.com/kodo/5914/s3-compatible-sts
|
||||
* 4、腾讯 临时密钥(临时访问凭证) GetFederationToken 临时密钥生成及使用指引 https://cloud.tencent.com/document/product/436/14048?from=10680
|
||||
* @param fileUrl 文件访问地址,全路径或者不是全路径都可以
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import java.io.File;
|
|||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
@Service()
|
||||
public class LocalFileServiceImpl implements IDfsService
|
||||
{
|
||||
private final LocalFileConfig localFileConfig;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import io.minio.http.Method;
|
|||
import io.minio.messages.Item;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -34,8 +36,8 @@ import java.util.function.Consumer;
|
|||
* http://docs.minio.org.cn/docs/master/java-client-api-reference#presignedGetObject
|
||||
* MinIO STS快速入门指南 http://docs.minio.org.cn/docs/master/minio-sts-quickstart-guide
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
//@Primary
|
||||
@Service()
|
||||
public class MinioDfsServiceImpl implements IDfsService
|
||||
{
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ import java.io.InputStream;
|
|||
*
|
||||
* 构建时间戳防盗链访问链接: https://developer.qiniu.com/kodo/1239/java#fusion-antileech
|
||||
*/
|
||||
//@Primary
|
||||
@Service
|
||||
@Primary
|
||||
@Service()
|
||||
public class QiniuDfsServiceImpl implements IDfsService {
|
||||
private static final Logger log = LoggerFactory.getLogger(QiniuDfsServiceImpl.class);
|
||||
@Autowired
|
||||
|
|
@ -76,7 +76,7 @@ public class QiniuDfsServiceImpl implements IDfsService {
|
|||
//解析上传成功的结果
|
||||
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||
/// http://guangdong-oss.ityun.ltd/dev/upload/default/20210717-133e3b4a-6aad-418c-a040-7161fa37ee49.jpeg
|
||||
return (domain + "/" + putRet.key).replace("//", "/") ;
|
||||
return (domain + "/" + putRet.key);
|
||||
} catch (QiniuException ex) {
|
||||
Response r = ex.response;
|
||||
String json = null;
|
||||
|
|
@ -118,8 +118,20 @@ public class QiniuDfsServiceImpl implements IDfsService {
|
|||
throw new CustomException("七牛云-获取文件占用空间功能,敬请期待");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileUrl http://guangdong-oss.ityun.ltd/dev/upload/default/20210722-b935b85a-fc25-44f6-9a85-e44c56a50a7e.jpeg
|
||||
* @return http://guangdong-oss.ityun.ltd/dev/upload/default/20210722-b935b85a-fc25-44f6-9a85-e44c56a50a7e.jpeg?e=1626970621&token=pRYrSe_EW4sJHsQ6JyuiRYShA2JCLKtMhT-N4TQD:-vq6Wm0mjv411wqj0SxIb_GZ1Q4=
|
||||
*/
|
||||
@Override
|
||||
public String presignedUrl(String fileUrl) {
|
||||
if (qiniuKodoConfig.getExpiryDuration() == -1) {
|
||||
return fileUrl;
|
||||
}
|
||||
//...其他参数参考类注释
|
||||
String accessKey = qiniuKodoConfig.getAccessKey();
|
||||
String secretKey = qiniuKodoConfig.getSecretKey();
|
||||
Auth auth = Auth.create(accessKey, secretKey);
|
||||
fileUrl = auth.privateDownloadUrl(fileUrl, qiniuKodoConfig.getExpiryDuration());
|
||||
return fileUrl;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue