Reputation: 13271
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
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