Skip to content

Commit 7f2eaf0

Browse files
author
Sabrina Juarez Garcia
committed
New Java SDK for Azure encodes the URL when it gets a BLOB Url. Decode it only for public containers.
1 parent 12972d9 commit 7f2eaf0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

gxcloudstorage-azureblob-latest/src/main/java/com/genexus/db/driver/ExternalProviderAzureStorageLatest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,14 @@ private String getResourceUrl(String externalFileName, ResourceAccessControlList
239239
return getPrivate(externalFileName, expirationMinutes);
240240
} else {
241241
BlobClient blobClient = publicContainerClient.getBlobClient(externalFileName);
242-
return blobClient.getBlobUrl();
242+
//getBlobClient method returns URL encoded
243+
//https://azuresdkdocs.z19.web.core.windows.net/java/azure-storage-blob/12.30.0/com/azure/storage/blob/BlobContainerClient.html#getBlobClient(java.lang.String)
244+
////https://github.com/Azure/azure-sdk-for-java/issues/21610
245+
246+
String url = blobClient.getBlobUrl();
247+
248+
//Decode only when not SAS
249+
return safeDecodeUrl(url);
243250
}
244251
}
245252

@@ -597,7 +604,18 @@ public String getObjectNameFromURL(String url) {
597604
}
598605
return objectName;
599606
}
600-
607+
608+
private static String safeDecodeUrl(String uri) {
609+
if (uri == null || uri.isEmpty()) return uri;
610+
boolean hasEncodedSegments = uri.matches(".*%[0-9A-Fa-f]{2}.*");
611+
if (!hasEncodedSegments) return uri;
612+
try {
613+
return java.net.URLDecoder.decode(uri);
614+
} catch (IllegalArgumentException e) {
615+
return uri;
616+
}
617+
}
618+
601619
private void handleAndLogException(String message, Exception ex) {
602620
if (ex instanceof BlobStorageException) {
603621
logger.error("Azure Storage error: {} (Status: {}, Code: {})",

0 commit comments

Comments
 (0)