mirror of
https://gitee.com/yudaocode/yudao-boot-mini.git
synced 2026-03-22 05:27:15 +08:00
feat:【infra】s3 生成 presignGetUrl 时需要对 path 进行解码,解决文件名是中文时访问不到文件
This commit is contained in:
@@ -13,6 +13,7 @@ import org.springframework.web.util.UriComponents;
|
|||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -35,6 +36,16 @@ public class HttpUtils {
|
|||||||
return URLEncoder.encode(value, StandardCharsets.UTF_8);
|
return URLEncoder.encode(value, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解码 URL 参数
|
||||||
|
*
|
||||||
|
* @param value 参数
|
||||||
|
* @return 解码后的参数
|
||||||
|
*/
|
||||||
|
public static String decodeUtf8(String value) {
|
||||||
|
return URLDecoder.decode(value, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static String replaceUrlQuery(String url, String key, String value) {
|
public static String replaceUrlQuery(String url, String key, String value) {
|
||||||
UrlBuilder builder = UrlBuilder.of(url, Charset.defaultCharset());
|
UrlBuilder builder = UrlBuilder.of(url, Charset.defaultCharset());
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
|||||||
public String presignGetUrl(String url, Integer expirationSeconds) {
|
public String presignGetUrl(String url, Integer expirationSeconds) {
|
||||||
// 1. 将 url 转换为 path
|
// 1. 将 url 转换为 path
|
||||||
String path = StrUtil.removePrefix(url, config.getDomain() + "/");
|
String path = StrUtil.removePrefix(url, config.getDomain() + "/");
|
||||||
path = HttpUtils.removeUrlQuery(path);
|
path = HttpUtils.decodeUtf8(HttpUtils.removeUrlQuery(path));
|
||||||
|
|
||||||
// 2.1 情况一:公开访问:无需签名
|
// 2.1 情况一:公开访问:无需签名
|
||||||
// 考虑到老版本的兼容,所以必须是 config.getEnablePublicAccess() 为 false 时,才进行签名
|
// 考虑到老版本的兼容,所以必须是 config.getEnablePublicAccess() 为 false 时,才进行签名
|
||||||
|
|||||||
Reference in New Issue
Block a user