mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-11-05 10:09:32 +08:00
支持获取七牛云文件公开下载链接和私有下载链接
This commit is contained in:
parent
e22dc339f0
commit
ef848ed13c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user