diff --git a/java/src/main/java/com/genexus/GxImageUtil.java b/java/src/main/java/com/genexus/GxImageUtil.java index e6bd325fb..975c27f6a 100644 --- a/java/src/main/java/com/genexus/GxImageUtil.java +++ b/java/src/main/java/com/genexus/GxImageUtil.java @@ -112,11 +112,22 @@ public static String crop(String imageFile, int x, int y, int width, int height) private static String writeImage(BufferedImage croppedImage, String destinationFilePathOrUrl) throws IOException { String newFileName = PrivateUtilities.getTempFileName(CommonUtil.getFileType(destinationFilePathOrUrl)); - try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { + IHttpContext httpContext = com.genexus.ModelContext.getModelContext().getHttpContext(); + try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()){ ImageIO.write(croppedImage, CommonUtil.getFileType(newFileName), outStream); - outStream.flush(); - byte[] imageInByte = outStream.toByteArray(); - return GXutil.blobFromBytes(imageInByte); + if (destinationFilePathOrUrl.toLowerCase().startsWith("http://") || destinationFilePathOrUrl.toLowerCase().startsWith("https://") || + (httpContext.isHttpContextWeb() && destinationFilePathOrUrl.startsWith(httpContext.getContextPath()))){ + try (ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray())) { + GXFile file = getGXFile(newFileName); + file.create(inStream, true); + file.close(); + return file.getURI(); + } + } else { + outStream.flush(); + byte[] imageInByte = outStream.toByteArray(); + return GXutil.blobFromBytes(imageInByte); + } } }