Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a image url in google appengine using java

The ImageIO is not in the whitelist of GAE. How to read a image(JPG,PNG) from url as ImageBuffer without using ImageIO?

like image 783
johnvip Avatar asked Nov 25 '25 23:11

johnvip


2 Answers

just use this Google App Engine built in API

byte[] b = URLFetchServiceFactory.getURLFetchService().fetch( url ).getContent();

No third party library required !!!

like image 144
Jitendra Rana Avatar answered Nov 27 '25 13:11

Jitendra Rana


You could read the url stream and create a bytearray using the IOUtils from apache commons.

URL url = new URL(this.url);
InputStream input = url.openStream();
byteArray = IOUtils.toByteArray(input)

Note:
toByteArray method buffers the input internally, so there is no need to use a BufferedInputStream.

EDIT:
BufferedImage is listed as not supported on AppEngine; that means that you CAN'T use that third party library on Google App Engine.

like image 33
systempuntoout Avatar answered Nov 27 '25 13:11

systempuntoout