【发布时间】:2012-12-18 21:17:34
【问题描述】:
我的服务调用返回图像。
它返回 png 图像,并且它的 header 中的 content-type 为 image/jpeg ,它在同一页面中打开图像。我想为用户提供将该图像保存到磁盘的选项。
【问题讨论】:
-
服务器响应中需要
Content-Disposition标头 -
谢谢。有没有例子,就可以了。
我的服务调用返回图像。
它返回 png 图像,并且它的 header 中的 content-type 为 image/jpeg ,它在同一页面中打开图像。我想为用户提供将该图像保存到磁盘的选项。
【问题讨论】:
Content-Disposition 标头
你需要Content-Disposition服务器的响应头
【讨论】:
return Response .ok(docStream, MediaType.APPLICATION_OCTET_STREAM) .header("content-disposition","attachment; filename = doc.rtf") .build();
Response,而不是byte[],并像我之前的评论一样返回
Content-Disposition 可以是内联的,将 content-disposition 指定为附件
response.setContentType("image/jpeg");
response.setHeader("Content-Disposition", "attachment; filename=" + imageName + ".jpg");
【讨论】: