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) {
4646 public static long getFileSize (String imageFile ){
4747 if (!isValidInput (imageFile ))
4848 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 ;
5165 }
5266
5367 public static int getImageHeight (String imageFile ) {
You can’t perform that action at this time.
0 commit comments