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
12 changes: 5 additions & 7 deletions java/src/main/java/com/genexus/GxImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;

import com.genexus.db.driver.ResourceAccessControlList;
import com.genexus.util.GxFileInfoSourceType;
Expand Down Expand Up @@ -49,13 +50,10 @@ public static long getFileSize(String imageFile){
IHttpContext httpContext = com.genexus.ModelContext.getModelContext().getHttpContext();
if (imageFile.toLowerCase().startsWith("http://") || imageFile.toLowerCase().startsWith("https://") ||
(httpContext.isHttpContextWeb() && imageFile.startsWith(httpContext.getContextPath()))){
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
BufferedImage image = ImageIO.read(new URL(GXDbFile.pathToUrl( imageFile, httpContext)).openStream());
String extension = imageFile.substring(imageFile.lastIndexOf(".") + 1);
ImageIO.write(image, extension, baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
return imageInByte.length;
try {
URL url = new URL(imageFile);
URLConnection connection = url.openConnection();
return Long.parseLong(connection.getHeaderField("Content-Length"));
} catch (Exception e) {
log.error("getFileSize " + imageFile + " failed" , e);
}
Expand Down