Skip to content

Commit a5dbef1

Browse files
Correct blob path in ImageAPI with external storage
Issue:102380
1 parent 4726715 commit a5dbef1

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,22 @@ public static String crop(String imageFile, int x, int y, int width, int height)
112112

113113
private static String writeImage(BufferedImage croppedImage, String destinationFilePathOrUrl) throws IOException {
114114
String newFileName = PrivateUtilities.getTempFileName(CommonUtil.getFileType(destinationFilePathOrUrl));
115-
try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) {
115+
IHttpContext httpContext = com.genexus.ModelContext.getModelContext().getHttpContext();
116+
try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()){
116117
ImageIO.write(croppedImage, CommonUtil.getFileType(newFileName), outStream);
117-
outStream.flush();
118-
byte[] imageInByte = outStream.toByteArray();
119-
return GXutil.blobFromBytes(imageInByte);
118+
if (destinationFilePathOrUrl.toLowerCase().startsWith("http://") || destinationFilePathOrUrl.toLowerCase().startsWith("https://") ||
119+
(httpContext.isHttpContextWeb() && destinationFilePathOrUrl.startsWith(httpContext.getContextPath()))){
120+
try (ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray())) {
121+
GXFile file = getGXFile(newFileName);
122+
file.create(inStream, true);
123+
file.close();
124+
return file.getURI();
125+
}
126+
} else {
127+
outStream.flush();
128+
byte[] imageInByte = outStream.toByteArray();
129+
return GXutil.blobFromBytes(imageInByte);
130+
}
120131
}
121132
}
122133

0 commit comments

Comments
 (0)