diff --git a/java/src/main/java/com/genexus/GxImageUtil.java b/java/src/main/java/com/genexus/GxImageUtil.java index bc7a3c0ed..f4f935968 100644 --- a/java/src/main/java/com/genexus/GxImageUtil.java +++ b/java/src/main/java/com/genexus/GxImageUtil.java @@ -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 ""; + } } }