johnvip
johnvip

Reputation: 53

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?

Upvotes: 3

Views: 1793

Answers (3)

Suma
Suma

Reputation: 34463

If you need to read the image content, not only its byte stream, the library https://github.com/pascalleclercq/appengine-awt does the job very well, just replace the usual imports with:

import com.google.code.appengine.awt.image.BufferedImage
import com.google.code.appengine.imageio.ImageIO

The library is published at Maven at https://mvnrepository.com/artifact/fr.opensagres.xdocreport.appengine-awt/appengine-awt/1.0.0

Upvotes: 0

systempuntoout
systempuntoout

Reputation: 74134

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.

Upvotes: 1

Jitendra Rana
Jitendra Rana

Reputation: 61

just use this Google App Engine built in API

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

No third party library required !!!

Upvotes: 6

Related Questions