Download image file from JAX-RS
来源:互联网 发布:java 接口开发demo 编辑:程序博客网 时间:2024/06/13 05:39
In JAX-RS, for user to download an image file, annotate the method with @Produces("image/image-type")
:
- Put
@Produces(“image/png”)
on service method, for “png
” image. - Set “
Content-Disposition
” in Response header to prompt a download box.
1. Download Image in JAX-RS
Full example to download an image file from JAX-RS.
import java.io.File;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.Produces;import javax.ws.rs.core.Response;import javax.ws.rs.core.Response.ResponseBuilder;@Path("/image")public class ImageService { private static final String FILE_PATH = "c:\\mkyong-logo.png"; @GET @Path("/get") @Produces("image/png") public Response getFile() { File file = new File(FILE_PATH); ResponseBuilder response = Response.ok((Object) file); response.header("Content-Disposition", "attachment; filename=image_from_server.png"); return response.build(); }}
2. Demo
Access this URI pattern : “/image/get
“.
Figure : Image file “c:\\mkyong-logo.png
” from server is prompted for user to download, with a new file name “image_from_server.png“
0 0
- Download image file from JAX-RS
- Download text file from JAX-RS
- Download pdf file from JAX-RS
- Download excel file from JAX-RS
- File Uploads with JAX-RS 2
- C# download file from webserver
- Download file from Web-Task1
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- image download from google by python
- wpf image绑定bitmap( Binding Image.Source from download memory)
- 飞思卡尔磁力计MAG3110 快速上手指南
- 【adoo】Van Emde Boas trees
- Rsyslog、Logrotate知识分享
- c++读取16进制文件
- Google Earth For Javascript 谷歌地球添加标记
- Download image file from JAX-RS
- hdu 5037 Frog(贪心)
- Google Earth For Javascript 谷歌地球删除所有标记
- php调用短信接口,php发送短信接口
- 提供语义分析和分词服务
- IOS-笔记16(Animation)
- 迭代模式
- 开发常用工具
- 为什么要使用SLF4J而不是Log4J