fix encode file name
This commit is contained in:
parent
9a0e84c50a
commit
38a6d24a89
1 changed files with 12 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ import org.micord.models.requests.S3Request;
|
|||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZoneOffset;
|
||||
|
|
@ -23,7 +24,7 @@ public class S3HttpConnection {
|
|||
String method = connectionParams.getMethod().toUpperCase();
|
||||
String body = connectionParams.getBody();
|
||||
|
||||
String resource = "/" + file;
|
||||
String resource = "/" + encodeFileName(file);
|
||||
String contentType = connectionParams.getContentType();
|
||||
String date = ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"));
|
||||
|
||||
|
|
@ -71,4 +72,14 @@ public class S3HttpConnection {
|
|||
return Base64.getEncoder().encodeToString(hash);
|
||||
}
|
||||
|
||||
public static String encodeFileName(String path) {
|
||||
String[] parts = path.split("/");
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
if (i > 0) result.append("/");
|
||||
result.append(URLEncoder.encode(parts[i], StandardCharsets.UTF_8));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue