Skip to content

Commit d97dead

Browse files
ImageWidth and ImageHeight wasn't working. (#651)
* ImageWidth and ImageHeigth wasnt working. Issue 100577 * Prettified code and reverted unnecessary changes * Dummy commit to force automatic merge Co-authored-by: Tomás Sexenian <tomas-sexenian@users.noreply.github.com> Co-authored-by: tomas-sexenian <tsexenian@genexus.com> Co-authored-by: iroqueta <46004974+iroqueta@users.noreply.github.com>
1 parent d00bffe commit d97dead

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

common/src/main/java/com/genexus/IHttpContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ public interface IHttpContext {
6363
boolean isHttpContextNull();
6464
boolean isHttpContextWeb();
6565

66-
66+
String getContextPath();
6767
}

java/src/main/java/com/genexus/GxImageUtil.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.awt.image.AffineTransformOp;
77
import java.awt.image.BufferedImage;
88
import java.io.*;
9+
import java.net.URL;
910

1011
import com.genexus.db.driver.ResourceAccessControlList;
1112
import com.genexus.util.GxFileInfoSourceType;
@@ -22,13 +23,19 @@ private static InputStream getInputStream(String filePathOrUrl) throws IOExcepti
2223

2324
private static BufferedImage createBufferedImageFromURI(String filePathOrUrl) throws IOException
2425
{
25-
try (InputStream is = getGXFile(filePathOrUrl).getStream()) {
26+
IHttpContext httpContext = com.genexus.ModelContext.getModelContext().getHttpContext();
27+
InputStream is = null;
28+
try{
29+
if (filePathOrUrl.toLowerCase().startsWith("http://") || filePathOrUrl.toLowerCase().startsWith("https://") ||
30+
(httpContext.isHttpContextWeb() && filePathOrUrl.startsWith(httpContext.getContextPath())))
31+
is = new URL(GXDbFile.pathToUrl( filePathOrUrl, httpContext)).openStream();
32+
else
33+
is = getGXFile(filePathOrUrl).getStream();
2634
return ImageIO.read(is);
27-
}
28-
catch (IOException e) {
35+
} catch (IOException e) {
2936
log.error("Failed to read image stream: " + filePathOrUrl);
3037
throw e;
31-
}
38+
} finally {is.close();}
3239
}
3340

3441
private static GXFile getGXFile(String filePathOrUrl) {

0 commit comments

Comments
 (0)