File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
java/src/main/java/com/genexus Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -46,8 +46,22 @@ private static GXFile getGXFile(String filePathOrUrl) {
46
46
public static long getFileSize (String imageFile ){
47
47
if (!isValidInput (imageFile ))
48
48
return INVALID_CODE ;
49
-
50
- return new GXFile (imageFile ).getLength ();
49
+ IHttpContext httpContext = com .genexus .ModelContext .getModelContext ().getHttpContext ();
50
+ if (imageFile .toLowerCase ().startsWith ("http://" ) || imageFile .toLowerCase ().startsWith ("https://" ) ||
51
+ (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 ;
59
+ } catch (Exception e ) {
60
+ log .error ("getFileSize " + imageFile + " failed" , e );
61
+ }
62
+ } else
63
+ return getGXFile (imageFile ).getLength ();
64
+ return INVALID_CODE ;
51
65
}
52
66
53
67
public static int getImageHeight (String imageFile ) {
You can’t perform that action at this time.
0 commit comments