How to read a image url in google appengine using java

此生再无相见时 提交于 2019-12-22 10:12:00

问题


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


回答1:


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.




回答2:


just use this Google App Engine built in API

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

No third party library required !!!




回答3:


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



来源:https://stackoverflow.com/questions/6856552/how-to-read-a-image-url-in-google-appengine-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!