Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions java/src/main/java/com/genexus/GxImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down