Skip to content

Commit 89abec5

Browse files
Sabrina Juarez GarciaBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:feature/Update_AzureStorage_SDK' into beta
1 parent b9d0050 commit 89abec5

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.azure.core.exception.ClientAuthenticationException;
44
import com.azure.core.exception.HttpRequestException;
5+
import com.azure.core.util.Context;
56
import com.azure.identity.DefaultAzureCredential;
67
import com.azure.identity.DefaultAzureCredentialBuilder;
78
import com.azure.storage.blob.BlobClient;
@@ -189,17 +190,30 @@ public String upload(String localFile, String externalFileName, ResourceAccessCo
189190
public String upload(String externalFileName, InputStream input, ResourceAccessControlList acl) {
190191
//https://docs.azure.cn/en-us/storage/blobs/storage-blob-upload-java
191192
try (ExternalProviderHelper.InputStreamWithLength streamInfo =
192-
ExternalProviderHelper.getInputStreamContentLength(input)) {
193+
ExternalProviderHelper.getInputStreamContentLength(input)) {
194+
193195
BlockBlobClient blobClient =
194-
getBlobClient(externalFileName, acl).getBlockBlobClient();
195-
// Set content type
196+
getBlobClient(externalFileName, acl).getBlockBlobClient();
197+
196198
String contentType =
197-
(externalFileName.endsWith(".tmp") &&
198-
"application/octet-stream".equals(streamInfo.detectedContentType))
199-
? "image/jpeg"
200-
: streamInfo.detectedContentType;
199+
(externalFileName.endsWith(".tmp") &&
200+
"application/octet-stream".equals(streamInfo.detectedContentType))
201+
? "image/jpeg"
202+
: streamInfo.detectedContentType;
203+
201204
BlobHttpHeaders headers = new BlobHttpHeaders().setContentType(contentType);
202-
blobClient.upload(streamInfo.inputStream, streamInfo.contentLength, true);
205+
blobClient.uploadWithResponse(
206+
streamInfo.inputStream,
207+
streamInfo.contentLength,
208+
headers,
209+
null,
210+
null,
211+
null,
212+
null,
213+
null,
214+
Context.NONE
215+
);
216+
203217
return getResourceUrl(externalFileName, acl, DEFAULT_EXPIRATION_MINUTES);
204218
}
205219
catch (Exception ex) {
@@ -281,9 +295,7 @@ public String copy(String objectName, String newName, ResourceAccessControlList
281295
try {
282296
BlobClient sourceBlob = getBlobClient(objectName, acl);
283297
BlobClient targetBlob = getBlobClient(newName, acl);
284-
285298
String sourceBlobUrl;
286-
287299
if (useManagedIdentity) {
288300
//Needs RBAC permissions: https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory
289301
sourceBlobUrl = sourceBlob.getBlobUrl();
@@ -334,7 +346,6 @@ public String copy(String objectUrl, String newName, String tableName, String fi
334346

335347
sourceBlobUrl = sourceBlob.getBlobUrl() + "?" + sourceBlob.generateSas(values);
336348
}
337-
338349
targetBlob.beginCopy(sourceBlobUrl, null);
339350
return getResourceUrl(newName, acl, defaultExpirationMinutes);
340351

@@ -398,7 +409,6 @@ public boolean existsDirectory(String directoryName) {
398409
try {
399410
// List all blobs with the directory prefix
400411
ListBlobsOptions options = new ListBlobsOptions().setPrefix(directoryName);
401-
402412
// Check if there are any blobs with this prefix
403413
boolean exists = false;
404414
for (BlobItem blobItem : publicContainerClient.listBlobs(options, null)) {
@@ -483,7 +493,6 @@ public void renameDirectory(String directoryName, String newDirectoryName) {
483493
}
484494
}
485495
}
486-
487496
// Delete the original directory
488497
deleteDirectory(directoryName);
489498
} catch (Exception ex) {

java/src/main/java/com/genexus/GXDbFile.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.genexus.util.GXServices;
66

77
import java.io.File;
8+
import java.net.URLDecoder;
9+
import java.nio.charset.StandardCharsets;
810
import java.util.regex.Matcher;
911
import java.util.regex.Pattern;
1012

@@ -26,6 +28,7 @@ public static String getFileName(String uri)
2628
{
2729
try
2830
{
31+
uri = safeDecodeUrl(uri);
2932
return CommonUtil.getFileName(uri);
3033
}
3134
catch (Exception e)
@@ -235,4 +238,20 @@ public static String pathToUrl(String path, boolean forceAbsPath)
235238
return pathToUrl(path, webContext, forceAbsPath);
236239
}
237240

241+
private static String safeDecodeUrl(String uri) {
242+
if (uri == null || uri.isEmpty()) {
243+
return uri;
244+
}
245+
boolean hasEncodedSegments =
246+
uri.matches(".*%[0-9A-Fa-f]{2}.*");
247+
248+
if (!hasEncodedSegments) {
249+
return uri;
250+
}
251+
try {
252+
return URLDecoder.decode(uri);
253+
} catch (IllegalArgumentException e) {
254+
return uri;
255+
}
256+
}
238257
}

0 commit comments

Comments
 (0)