How to read image url in google appengine using java

ImageIO is not a GAE whitelist. How to read image (jpg, png) with url as ImageBuffer without using ImageIO?

+3
source share
3 answers

You can read the url stream and create a bytearray using IOUtils from apache shared resources.

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 BufferedInputStream .

EDIT:
BufferedImage is listed as not supported by AppEngine; this means that you CANNOT use this third-party library in the Google App Engine.

+1
source

just use this google app engine built into the API

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

No third-party library required !!!

+6
source

If you need to read the contents of an image, and not just its stream of bytes, the https://github.com/pascalleclercq/appengine-awt library does the job very well, just replace the regular import:

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

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

0
source

Source: https://habr.com/ru/post/947731/


All Articles