From 642f51716ca0b5c0bb2a2074405001810fc0f378 Mon Sep 17 00:00:00 2001 From: tomas-sexenian Date: Wed, 12 Apr 2023 12:44:30 -0300 Subject: [PATCH 1/3] Filesize fix, return exact size value without dowloading image Issue:102319 --- java/src/main/java/com/genexus/GxImageUtil.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/java/src/main/java/com/genexus/GxImageUtil.java b/java/src/main/java/com/genexus/GxImageUtil.java index d3904ed3f..5309ceb4e 100644 --- a/java/src/main/java/com/genexus/GxImageUtil.java +++ b/java/src/main/java/com/genexus/GxImageUtil.java @@ -7,6 +7,7 @@ import java.awt.image.BufferedImage; import java.io.*; import java.net.URL; +import java.net.URLConnection; import com.genexus.db.driver.ResourceAccessControlList; import com.genexus.util.GxFileInfoSourceType; @@ -49,13 +50,11 @@ public static long getFileSize(String imageFile){ IHttpContext httpContext = com.genexus.ModelContext.getModelContext().getHttpContext(); if (imageFile.toLowerCase().startsWith("http://") || imageFile.toLowerCase().startsWith("https://") || (httpContext.isHttpContextWeb() && imageFile.startsWith(httpContext.getContextPath()))){ - try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - BufferedImage image = ImageIO.read(new URL(GXDbFile.pathToUrl( imageFile, httpContext)).openStream()); - String extension = imageFile.substring(imageFile.lastIndexOf(".") + 1); - ImageIO.write(image, extension, baos); - baos.flush(); - byte[] imageInByte = baos.toByteArray(); - return imageInByte.length; + try { + URL url = new URL(imageFile); + URLConnection connection = url.openConnection(); + connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"); + return Long.parseLong(connection.getHeaderField("Content-Length")); } catch (Exception e) { log.error("getFileSize " + imageFile + " failed" , e); } From ff995e107313f61d7c2db5126406546fe12629d7 Mon Sep 17 00:00:00 2001 From: tomas-sexenian Date: Wed, 12 Apr 2023 17:38:55 -0300 Subject: [PATCH 2/3] Removed user agent request property --- java/src/main/java/com/genexus/GxImageUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/java/src/main/java/com/genexus/GxImageUtil.java b/java/src/main/java/com/genexus/GxImageUtil.java index 5309ceb4e..9c831a32e 100644 --- a/java/src/main/java/com/genexus/GxImageUtil.java +++ b/java/src/main/java/com/genexus/GxImageUtil.java @@ -53,7 +53,6 @@ public static long getFileSize(String imageFile){ try { URL url = new URL(imageFile); URLConnection connection = url.openConnection(); - connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"); return Long.parseLong(connection.getHeaderField("Content-Length")); } catch (Exception e) { log.error("getFileSize " + imageFile + " failed" , e); From 9e838266bd8e076dbc1effa4c2e9e01d64f730de Mon Sep 17 00:00:00 2001 From: tomas-sexenian Date: Fri, 14 Apr 2023 12:49:45 -0300 Subject: [PATCH 3/3] filesize fix, correct filesize for linked KB image --- java/src/main/java/com/genexus/GxImageUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/main/java/com/genexus/GxImageUtil.java b/java/src/main/java/com/genexus/GxImageUtil.java index 9c831a32e..e6bd325fb 100644 --- a/java/src/main/java/com/genexus/GxImageUtil.java +++ b/java/src/main/java/com/genexus/GxImageUtil.java @@ -51,7 +51,7 @@ public static long getFileSize(String imageFile){ if (imageFile.toLowerCase().startsWith("http://") || imageFile.toLowerCase().startsWith("https://") || (httpContext.isHttpContextWeb() && imageFile.startsWith(httpContext.getContextPath()))){ try { - URL url = new URL(imageFile); + URL url = new URL(GXDbFile.pathToUrl(imageFile, httpContext)); URLConnection connection = url.openConnection(); return Long.parseLong(connection.getHeaderField("Content-Length")); } catch (Exception e) {