临时授权加上-不保存file至本地db
This commit is contained in:
parent
8bb392446f
commit
0593e4dd6e
@ -894,7 +894,25 @@ public class FileServiceImpl implements FileService {
|
||||
// bucket下的key
|
||||
String tgtFileKey = Utility.generateFileKey(item.getDirectory(), item.getFileUuid(), item.getFileFormat());
|
||||
String bucketType = StringUtils.isNotBlank(bucketTypeMap.get(item.getAppChannelBucketNo())) ? bucketTypeMap.get(item.getAppChannelBucketNo()) : BucketTypeEnum.PRIVATE_BUCKET.getCode();
|
||||
return this.buildSignUrlDownloadResponse(bucketType, item.getBucketName(), tgtFileKey, item.getChannelCode(), item.getFileUuid(), item.getFileName(), style, hasFileName, expire);
|
||||
switch (BucketTypeEnum.getByCode(bucketType)) {
|
||||
case PUBLIC_BUCKET://公有桶 - 永久链接,例如 http://xxx.png
|
||||
String url = this.fileManager.fetchDownloadUrl(item.getBucketName(), tgtFileKey, item.getChannelCode());
|
||||
return SignUrlDownloadResponse.builder()
|
||||
.signUrl(this.buildPublicXImageProcess(url, style))
|
||||
.fileKey(item.getFileUuid())
|
||||
.fileName(item.getFileName())
|
||||
.build();
|
||||
case PRIVATE_BUCKET://私有桶 - 临时授权链接 例如 http://xxx.png?Expire=a&AccessKeyId=b&Signature=c&repsonse-content-disposition=d
|
||||
String signUrl = this.fileManager.signUrlDownload(item.getBucketName(), tgtFileKey, Objects.nonNull(expire) ? expire : SIGN_URL_DOWNLOAD_EXPIRE_SECOND , item.getChannelCode(), item.getFileName(), style, hasFileName);
|
||||
return SignUrlDownloadResponse.builder()
|
||||
.signUrl(UrlUtil.httpToHttps(signUrl))
|
||||
.fileKey(item.getFileUuid())
|
||||
.fileName(item.getFileName())
|
||||
.build();
|
||||
default:
|
||||
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
|
||||
}
|
||||
return SignUrlDownloadResponse.builder().build();
|
||||
}).collect(Collectors.toList());
|
||||
return responseList;
|
||||
}
|
||||
@ -906,27 +924,22 @@ public class FileServiceImpl implements FileService {
|
||||
* @param tgtFileKey 桶key
|
||||
* @param channelCode aliyun/huaweicloud
|
||||
* @param fileUuid 文件标识
|
||||
* @param fileName 文件名称
|
||||
* @param style 裁剪样式
|
||||
* @param hasFileName 是否显示文件名称
|
||||
* @param expire 过期时间
|
||||
* @return 临时授权下载返回对象
|
||||
*/
|
||||
private SignUrlDownloadResponse buildSignUrlDownloadResponse(String bucketType, String bucketName, String tgtFileKey, String channelCode, String fileUuid, String fileName, String style, Boolean hasFileName,Long expire) {
|
||||
private SignUrlDownloadResponse buildSignUrlDownloadResponse(String bucketType, String bucketName, String tgtFileKey, String channelCode, String fileUuid, Long expire) {
|
||||
switch (BucketTypeEnum.getByCode(bucketType)) {
|
||||
case PUBLIC_BUCKET://公有桶 - 永久链接,例如 http://xxx.png
|
||||
String url = this.fileManager.fetchDownloadUrl(bucketName, tgtFileKey, channelCode);//item.getBucketName() item.getChannelCode()
|
||||
return SignUrlDownloadResponse.builder()
|
||||
.signUrl(this.buildPublicXImageProcess(url, style))
|
||||
.signUrl(this.buildPublicXImageProcess(url, null))
|
||||
.fileKey(fileUuid)//item.getFileUuid()
|
||||
.fileName(fileName)//item.getFileName()
|
||||
.build();
|
||||
case PRIVATE_BUCKET://私有桶 - 临时授权链接 例如 http://xxx.png?Expire=a&AccessKeyId=b&Signature=c&repsonse-content-disposition=d
|
||||
String signUrl = this.fileManager.signUrlDownload(bucketName, tgtFileKey, Objects.nonNull(expire) ? expire : SIGN_URL_DOWNLOAD_EXPIRE_SECOND , channelCode, fileName, style, hasFileName);
|
||||
String signUrl = this.fileManager.signUrlDownload(bucketName, tgtFileKey, Objects.nonNull(expire) ? expire : SIGN_URL_DOWNLOAD_EXPIRE_SECOND , channelCode, null, null, false);
|
||||
return SignUrlDownloadResponse.builder()
|
||||
.signUrl(UrlUtil.httpToHttps(signUrl))
|
||||
.fileKey(fileUuid)
|
||||
.fileName(fileName)
|
||||
.build();
|
||||
default:
|
||||
BizException.error(CodeEnum.CHANNEL_TYPE_NOT_EXIST);
|
||||
@ -1124,7 +1137,7 @@ public class FileServiceImpl implements FileService {
|
||||
return dto.getFileKeys().stream().map(item ->{
|
||||
//构建返回集合
|
||||
return this.buildSignUrlDownloadResponse(appChannelBucket.getBucketType(), appChannelBucket.getBucketName()
|
||||
, item, appChannelBucket.getChannelCode(), item, null, null, false, scene.getDownloadExpiration());
|
||||
, item, appChannelBucket.getChannelCode(), item, scene.getDownloadExpiration());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user