Skip to content

Commit 1fd9380

Browse files
Filesize fix, return exact size value without downloading image (#705)
* Filesize fix, return exact size value without dowloading image Issue:102319 * Removed user agent request property --------- Co-authored-by: tomas-sexenian <tsexenian@genexus.com>
1 parent c2030e8 commit 1fd9380

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.awt.image.BufferedImage;
88
import java.io.*;
99
import java.net.URL;
10+
import java.net.URLConnection;
1011

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

0 commit comments

Comments
 (0)