Skip to content

Commit

Permalink
fix: download key has prefix /
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed May 15, 2024
1 parent 7a951c6 commit ddb92a8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/main/java/com/qiniu/storage/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,7 @@ public String getPath() throws QiniuException {
* @throws QiniuException 组装 query 时的异常,一般为缺失必要参数的异常
*/
protected void buildPath() throws QiniuException {
path = StringUtils.join(pathSegments, "/");
if (!path.startsWith("/")) {
path = "/" + path;
}
path = "/" + StringUtils.join(pathSegments, "/");
}


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/qiniu/storage/ApiUploadV1MakeFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ protected void buildPath() throws QiniuException {
addPathSegment(UrlSafeBase64.encodeToString(key));
}

if (params != null && params.size() > 0) {
if (params != null && !params.isEmpty()) {
for (String key : params.keySet()) {
addPathSegment(key);
addPathSegment(UrlSafeBase64.encodeToString("" + params.get(key)));
}
}

if (metaDataParam != null && metaDataParam.size() > 0) {
if (metaDataParam != null && !metaDataParam.isEmpty()) {
for (String key : metaDataParam.keySet()) {
addPathSegment(key);
addPathSegment(UrlSafeBase64.encodeToString("" + metaDataParam.get(key)));
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/test/com/qiniu/storage/DownloadUrlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -59,6 +61,7 @@ public void testSpecialKey() {
{
put("", "");
put("abc_def.mp4", "abc_def.mp4");
put("/ab/cd", "/ab/cd");
put("ab/cd", "ab/cd");
put("ab/中文/de", "ab/%E4%B8%AD%E6%96%87/de");
put("ab+-*de f", "ab%2B-%2Ade%20f");
Expand Down

0 comments on commit ddb92a8

Please sign in to comment.