Minio配置、aliyun oss、qiuniu kado 文件加签访问 测试完成,没有问题

pull/84/head
duandazhi 4 years ago
parent 69dc496580
commit f412996375

@ -7,6 +7,7 @@ import org.springframework.context.annotation.Configuration;
/** /**
* aliyun oss https://help.aliyun.com/learn/learningpath/oss.html ,需要购买 * 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 * @author dazer
* *
@ -52,6 +53,11 @@ public class AliyunOssConfig {
* -1 url * -1 url
* URL360032400 * URL360032400
* 访 https://help.aliyun.com/document_detail/32016.html?spm=a2c4g.11186623.6.996.335b6d13O5xgUH * 访 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; private Long expiryDuration = 32400L;

@ -8,7 +8,6 @@ import org.springframework.context.annotation.Configuration;
import io.minio.MinioClient; import io.minio.MinioClient;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/** /**
* Minio * Minio
@ -55,6 +54,12 @@ public class MinioConfig {
/** /**
* 访; url访ip * 访; url访ip
* eg: https://yq666.bj.gov.cn/appt-file * eg: https://yq666.bj.gov.cn/appt-file
*
* minio Bucket Policy Bucket ==> Edit Bucket
* 1Read Only
* 2Write Only
* 3Read and Write
* 4 访
*/ */
private String domain; private String domain;

@ -39,6 +39,18 @@ public class QiniuKodoConfig {
private String secretKey; private String secretKey;
private String bucketName; private String bucketName;
private String domain; private String domain;
/**
*
* 13600L
* 932400L
* 1243200L, 11
* -1 url
* URL360032400
*
* qoniu oss Bucket访 https://developer.qiniu.com/kodo/1202/download-token
* (Bucket )==使======
*/
private Long expiryDuration = 32400L;
public String getAccessKey() { public String getAccessKey() {
return accessKey; return accessKey;
@ -71,4 +83,16 @@ public class QiniuKodoConfig {
public void setDomain(String domain) { public void setDomain(String domain) {
this.domain = 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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;
@ -42,7 +43,7 @@ import java.util.concurrent.TimeUnit;
* //@see AliyunMsgUtil * //@see AliyunMsgUtil
*/ */
//@Primary //@Primary
@Service @Service()
public class AliyunOssDsfServiceImpl implements IDfsService { public class AliyunOssDsfServiceImpl implements IDfsService {
private static final Logger log = LoggerFactory.getLogger(AliyunOssDsfServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(AliyunOssDsfServiceImpl.class);
@Autowired @Autowired
@ -516,6 +517,10 @@ public class AliyunOssDsfServiceImpl implements IDfsService {
return result; 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 @Override
public String presignedUrl(String fileUrl) { public String presignedUrl(String fileUrl) {
if (aliyunOssConfig.getExpiryDuration() == -1) { if (aliyunOssConfig.getExpiryDuration() == -1) {

@ -35,7 +35,7 @@ import javax.annotation.PostConstruct;
* 2:ceph使docker https://www.cnblogs.com/bladeyul/p/10649049.html * 2:ceph使docker https://www.cnblogs.com/bladeyul/p/10649049.html
* 3:使docker ceph 使aws sdk https://blog.csdn.net/freewebsys/article/details/79553386 * 3:使docker ceph 使aws sdk https://blog.csdn.net/freewebsys/article/details/79553386
*/ */
@Service @Service()
public class CephDfsServiceImpl implements IDfsService { public class CephDfsServiceImpl implements IDfsService {
private static final Logger log = LoggerFactory.getLogger(CephDfsServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(CephDfsServiceImpl.class);
@Autowired @Autowired

@ -18,7 +18,7 @@ import com.github.tobato.fastdfs.service.FastFileStorageClient;
* @author ruoyi * @author ruoyi
* @see FastDfsConfig * @see FastDfsConfig
*/ */
@Service @Service()
public class FastDfsServiceImpl implements IDfsService public class FastDfsServiceImpl implements IDfsService
{ {
private final Logger logger = LoggerFactory.getLogger(FastDfsServiceImpl.class); private final Logger logger = LoggerFactory.getLogger(FastDfsServiceImpl.class);

@ -17,7 +17,7 @@ import java.io.IOException;
* ftp, iislinux ftpvsftpdFileZilla Server * ftp, iislinux ftpvsftpdFileZilla Server
* @author dazer * @author dazer
*/ */
@Service @Service()
public class FtpFileServiceImpl implements IDfsService { public class FtpFileServiceImpl implements IDfsService {
@Autowired @Autowired
private FtpConfig ftpConfig; private FtpConfig ftpConfig;

@ -73,7 +73,7 @@ public interface IDfsService
* 2minio resignedGetObject Security Token ServiceSTS; Presigned presignedGetObject * 2minio resignedGetObject Security Token ServiceSTS; Presigned presignedGetObject
* http://docs.minio.org.cn/docs/master/minio-sts-quickstart-guide * 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 * minio SDKS Java Client API http://docs.minio.org.cn/docs/master/java-client-api-reference
* 3qiniu 访 https://developer.qiniu.com/kodo/1239/java#fusion-antileech * 3qiniu (Bucket )==使====== https://developer.qiniu.com/kodo/1202/download-token
* https://developer.qiniu.com/kodo/5914/s3-compatible-sts * https://developer.qiniu.com/kodo/5914/s3-compatible-sts
* 4 访 GetFederationToken 使 https://cloud.tencent.com/document/product/436/14048?from=10680 * 4 访 GetFederationToken 使 https://cloud.tencent.com/document/product/436/14048?from=10680
* @param fileUrl 访, * @param fileUrl 访,

@ -16,7 +16,7 @@ import java.io.File;
* *
* @author ruoyi * @author ruoyi
*/ */
@Service @Service()
public class LocalFileServiceImpl implements IDfsService public class LocalFileServiceImpl implements IDfsService
{ {
private final LocalFileConfig localFileConfig; private final LocalFileConfig localFileConfig;

@ -7,6 +7,8 @@ import io.minio.http.Method;
import io.minio.messages.Item; import io.minio.messages.Item;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 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.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;
@ -34,8 +36,8 @@ import java.util.function.Consumer;
* http://docs.minio.org.cn/docs/master/java-client-api-reference#presignedGetObject * 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 * MinIO STS http://docs.minio.org.cn/docs/master/minio-sts-quickstart-guide
*/ */
@Primary //@Primary
@Service @Service()
public class MinioDfsServiceImpl implements IDfsService public class MinioDfsServiceImpl implements IDfsService
{ {
@Autowired @Autowired

@ -32,8 +32,8 @@ import java.io.InputStream;
* *
* 访 https://developer.qiniu.com/kodo/1239/java#fusion-antileech * 访 https://developer.qiniu.com/kodo/1239/java#fusion-antileech
*/ */
//@Primary @Primary
@Service @Service()
public class QiniuDfsServiceImpl implements IDfsService { public class QiniuDfsServiceImpl implements IDfsService {
private static final Logger log = LoggerFactory.getLogger(QiniuDfsServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(QiniuDfsServiceImpl.class);
@Autowired @Autowired
@ -76,7 +76,7 @@ public class QiniuDfsServiceImpl implements IDfsService {
//解析上传成功的结果 //解析上传成功的结果
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class); DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
/// http://guangdong-oss.ityun.ltd/dev/upload/default/20210717-133e3b4a-6aad-418c-a040-7161fa37ee49.jpeg /// 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) { } catch (QiniuException ex) {
Response r = ex.response; Response r = ex.response;
String json = null; String json = null;
@ -118,8 +118,20 @@ public class QiniuDfsServiceImpl implements IDfsService {
throw new CustomException("七牛云-获取文件占用空间功能,敬请期待"); 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 @Override
public String presignedUrl(String fileUrl) { 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; return fileUrl;
} }

Loading…
Cancel
Save