Commit 8aaead39bca6759dea3911a7abc83701cd12e906
1 parent
cdc4255d
feat:【infra】s3 生成 presignGetUrl 时需要对 path 进行解码,解决文件名是中文时访问不到文件
Showing
2 changed files
with
12 additions
and
1 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java
| ... | ... | @@ -13,6 +13,7 @@ import org.springframework.web.util.UriComponents; |
| 13 | 13 | import org.springframework.web.util.UriComponentsBuilder; |
| 14 | 14 | |
| 15 | 15 | import java.net.URI; |
| 16 | +import java.net.URLDecoder; | |
| 16 | 17 | import java.net.URLEncoder; |
| 17 | 18 | import java.nio.charset.Charset; |
| 18 | 19 | import java.nio.charset.StandardCharsets; |
| ... | ... | @@ -35,6 +36,16 @@ public class HttpUtils { |
| 35 | 36 | return URLEncoder.encode(value, StandardCharsets.UTF_8); |
| 36 | 37 | } |
| 37 | 38 | |
| 39 | + /** | |
| 40 | + * 解码 URL 参数 | |
| 41 | + * | |
| 42 | + * @param value 参数 | |
| 43 | + * @return 解码后的参数 | |
| 44 | + */ | |
| 45 | + public static String decodeUtf8(String value) { | |
| 46 | + return URLDecoder.decode(value, StandardCharsets.UTF_8); | |
| 47 | + } | |
| 48 | + | |
| 38 | 49 | @SuppressWarnings("unchecked") |
| 39 | 50 | public static String replaceUrlQuery(String url, String key, String value) { |
| 40 | 51 | UrlBuilder builder = UrlBuilder.of(url, Charset.defaultCharset()); | ... | ... |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/s3/S3FileClient.java
| ... | ... | @@ -116,7 +116,7 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> { |
| 116 | 116 | public String presignGetUrl(String url, Integer expirationSeconds) { |
| 117 | 117 | // 1. 将 url 转换为 path |
| 118 | 118 | String path = StrUtil.removePrefix(url, config.getDomain() + "/"); |
| 119 | - path = HttpUtils.removeUrlQuery(path); | |
| 119 | + path = HttpUtils.decodeUtf8(HttpUtils.removeUrlQuery(path)); | |
| 120 | 120 | |
| 121 | 121 | // 2.1 情况一:公开访问:无需签名 |
| 122 | 122 | // 考虑到老版本的兼容,所以必须是 config.getEnablePublicAccess() 为 false 时,才进行签名 | ... | ... |