How to read a image url in google appengine using

2019-05-14 12:08发布

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

3条回答
做自己的国王
2楼-- · 2019-05-14 12:18

just use this Google App Engine built in API

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

No third party library required !!!

查看更多
beautiful°
3楼-- · 2019-05-14 12:30

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.

查看更多
贪生不怕死
4楼-- · 2019-05-14 12:34

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

查看更多
登录 后发表回答