【问题标题】:Give the option to save the image提供保存图像的选项
【发布时间】:2012-12-18 21:17:34
【问题描述】:

我的服务调用返回图像。

它返回 png 图像,并且它的 header 中的 content-type 为 image/jpeg ,它在同一页面中打开图像。我想为用户提供将该图像保存到磁盘的选项。

【问题讨论】:

  • 服务器响应中需要Content-Disposition 标头
  • 谢谢。有没有例子,就可以了。

标签: java html image


【解决方案1】:

你需要Content-Disposition服务器的响应头

For example

【讨论】:

  • 感谢您的示例。好吧,我在这里使用的是 java 的 jersey web 服务,但不知道如何在此处执行此操作。
  • 看这几行:return Response .ok(docStream, MediaType.APPLICATION_OCTET_STREAM) .header("content-disposition","attachment; filename = doc.rtf") .build();
  • 但是 @GET @Produces("image/jpeg") public byte[] ,这是我的代码,它仍然在同一个浏览器中打开。
  • 你应该返回Response,而不是byte[],并像我之前的评论一样返回
【解决方案2】:

Content-Disposition 可以是内联的,将 content-disposition 指定为附件

response.setContentType("image/jpeg");
response.setHeader("Content-Disposition", "attachment; filename=" + imageName + ".jpg");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多