开发者

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,开发者_JAVA百科PNG) from url as ImageBuffer without using ImageIO?


just use this Google App Engine built in API

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

No third party library required !!!


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜