Google 应用引擎显示图像
我在显示从 Google App Engine Java 中的 DataStore 抓取的图像时遇到问题。
Servlet 代码:
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;
}
使用的图像 src url:
<img src="/image?type=showImage" />
可能缺少某些内容,只是无法弄清楚是什么。我已经对其进行了调试,代码已运行,并且 blob 包含数据,但图像根本没有显示。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JPEG 图像的正确 MIME 类型是
image/jpeg
而不是image/jpg
(请参阅此 参考),并且某些网络浏览器似乎不接受image/jpg
。您可以使用
response.setContentType("image/jpeg");
尝试相同的代码。The right MIME type for JPEG images is
image/jpeg
and notimage/jpg
(see this reference) and it seems that some web browsers don't acceptimage/jpg
.You can try the same code with
response.setContentType("image/jpeg");
.