Is the server on which your JPEG is hosted especially slow? Note that the
default timeout limit for URL Fetch requests is 5 seconds. You can increase
this up to 10 by passing 10000 (ms) into setConnectTimeout().

Also keep in mind that your image will have to be smaller than 1 MB if
you're planning to use it with the Images service or store it in the
datastore.

- Jason

On Wed, Oct 28, 2009 at 8:37 AM, nicanor.babula <[email protected]>wrote:

>
> Hello everyone,
>
> I have somewhere on the net a servlet that serves jpeg images. In
> order to verify that it works I made a html page with:
> <img src="http://myurl/servlet?id=123"; />
> and the image is displayed well.
>
> Now, I am trying to create an GAE image object from the data arriving
> from that servlet. How can I do?
> So far I tried this code*[1], with a lot of variations, and I keep
> getting timeouts and "The API call urlfetch.Fetch() took too long to
> respond and was cancelled." error message in my application's logs.
>
> Locally, in the development server, it works.
>
> I also tried storing this images in the datastore and serving them
> directly from GAE.
> Example of image url: http://almaoffice0.appspot.com/GetImage?id=24001
>
>
> Any ideas?
>
> *[1]: the code:
>
>       ImagesService imagesService =
> ImagesServiceFactory.getImagesService();
>        try {
>            URL url = new URL(stringUrl);
>            HttpURLConnection connection = (HttpURLConnection)
> url.openConnection();
>            connection.setRequestMethod("GET");
>            connection.setReadTimeout(0);
>            connection.setRequestProperty("ContentType", "image/
> jpeg");
>            connection.setDoInput(true);
>
>            if(connection.getResponseCode() ==
> HttpURLConnection.HTTP_OK){
>                InputStream in = connection.getInputStream();
>                byte[] imgData = new byte[in.available()];
>                in.read(imgData);
>                Image oldImg = ImagesServiceFactory.makeImage
> (imgData);
>                Transform resize = ImagesServiceFactory.makeResize
> (oldImg.getWidth(), oldImg.getHeight());
>                 // I do an useless transformation, in order to force
> the conversion to jpeg
>                return imagesService.applyTransform(resize, oldImg,
> ImagesService.OutputEncoding.JPEG);
>            } else {
>                throw new Exception("cannot retrieve image @ " +
> stringUrl);
>            }
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to