From ef848ed13c86619560ca436bc4b96b7dd74d1649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=E5=98=89=E9=98=B3?= Date: Sat, 20 Feb 2021 10:29:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96=E4=B8=83?= =?UTF-8?q?=E7=89=9B=E4=BA=91=E6=96=87=E4=BB=B6=E5=85=AC=E5=BC=80=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E9=93=BE=E6=8E=A5=E5=92=8C=E7=A7=81=E6=9C=89=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/core/oss/QiniuTemplate.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java index 46f4c85..7304fe0 100644 --- a/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java +++ b/blade-core-oss/src/main/java/org/springblade/core/oss/QiniuTemplate.java @@ -33,6 +33,8 @@ import org.springblade.core.tool.utils.StringPool; import org.springframework.web.multipart.MultipartFile; import java.io.InputStream; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.List; @@ -127,6 +129,33 @@ public class QiniuTemplate { } + /** + * 获取文件公开链接 + * + * @param fileName 文件名 + * @return 文件公开链接 + * @link https://developer.qiniu.com/kodo/1239/java#public-get + */ + public String publicFileLink(String fileName) { + return String.format("%s/%s", ossProperties.getEndpoint(), fileName); + } + + /** + * 获取文件私有链接 + * + * @param fileName 文件名 + * @param expireTime 超时时间 + * @return 私有文件链接 + * @link https://developer.qiniu.com/kodo/1239/java#private-get + */ + @SneakyThrows + public String privateFileLink(String fileName, Long expireTime) { + String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()).replace("+", "%20"); + String publicUrl = String.format("%s/%s", ossProperties.getEndpoint(), encodedFileName); + return auth.privateDownloadUrl(publicUrl, expireTime); + } + + @SneakyThrows public BladeFile putFile(MultipartFile file) { return putFile(ossProperties.getBucketName(), file.getOriginalFilename(), file);