user373455
user373455

Reputation: 13271

Google app engine show image

I've a problem showing an image grabbed from the DataStore in Google App Engine Java.

Servlet code:

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
    String type=request.getParameter("type");

    if(type != null)
    {
        if(type.equalsIgnoreCase("showImage"))
        {
            Blob blob = this.retrieveImage();
            response.setContentType("image/jpg");
            response.getOutputStream().write(blob.getBytes());  
        }
    }
}

private Blob retrieveImage()
{
    GetImageQuery query = new GetImageQuery ();
    List<ImageData> listImages=query.getImages();

    Blob blobImage = listImages.get(0).getImage();
    return blobImage;
}

Image src url used:

<img src="/image?type=showImage" />

Something's probably missing, just can't figure out what. I've debugged it and the code is run and the blob contains data but an image is simply not showing.

Upvotes: 1

Views: 1523

Answers (1)

olivierlemasle
olivierlemasle

Reputation: 1229

The right MIME type for JPEG images is image/jpeg and not image/jpg (see this reference) and it seems that some web browsers don't accept image/jpg.

You can try the same code with response.setContentType("image/jpeg");.

Upvotes: 1

Related Questions