Skip to content

Commit

Permalink
Only encode file name and not the entire path
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-sexenian committed Jan 29, 2024
1 parent 24ec296 commit f68fc37
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,20 @@ private String getResourceUrl(String externalFileName, ResourceAccessControlList
return presignedGetObjectRequest.url().toString();
} else {
try {
return String.format(
"https://%s.s3.%s.amazonaws.com/%s",
int lastIndex = Math.max(externalFileName.lastIndexOf('/'), externalFileName.lastIndexOf('\\'));
String path = externalFileName.substring(0, lastIndex + 1);
String fileName = externalFileName.substring(lastIndex + 1);
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());

String url = String.format(
"https://%s.s3.%s.amazonaws.com/%s%s",
bucket,
clientRegion,
URLEncoder.encode(
externalFileName,
StandardCharsets.UTF_8.toString()
)
path,
encodedFileName
);

return url;
} catch (UnsupportedEncodingException uee) {
logger.error("Failed to encode resource URL for " + externalFileName, uee);
return "";
Expand Down

0 comments on commit f68fc37

Please sign in to comment.