Skip to content

Commit

Permalink
generated images go to temp media dir
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-sexenian committed Mar 9, 2023
1 parent 7888f4a commit ee7e64d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions java/src/main/java/com/genexus/GxImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ 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(destinationFilePathOrUrl.substring(destinationFilePathOrUrl.lastIndexOf(".") + 1));
try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) {
ImageIO.write(croppedImage, CommonUtil.getFileType(destinationFilePathOrUrl), outStream);
outStream.flush();
byte[] imageInByte = outStream.toByteArray();
return GXutil.blobFromBytes(imageInByte);
} catch (IOException e) {
log.error("writeImage " + destinationFilePathOrUrl + " failed" , e);
return "";
ImageIO.write(croppedImage, CommonUtil.getFileType(newFileName), outStream);
try (ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray())) {
String filePath = Preferences.getDefaultPreferences().getPRIVATE_PATH() + newFileName;
GXFile file = getGXFile(filePath);
file.create(inStream, true);
file.close();
return filePath;
} catch (IOException e) {
log.error("writeImage " + destinationFilePathOrUrl + " failed" , e);
return "";
}
}
}

Expand Down

0 comments on commit ee7e64d

Please sign in to comment.