[英]image-bytes to Rest
I have stored image in database and I want it expose via rest. 我已将图像存储在数据库中,并且希望通过休息将其公开。 What is the best way?
什么是最好的方法?
@Path("/image/{imageId}.jpeg")
@Stateless
@Produces({"image/jpeg"})
public class ImageSource{
@PersistenceContext
EntityManager em;
@GET
public /* what */ getImage(@PathParam("imageId") Long imageId) throws IOException{
byte[] image = em.find(Entity1.class, imageId).getImage();
// something here
}
}
You need a Response created by the builder method. 您需要使用builder方法创建的Response。
See Representations and Java types . 请参见制图表达和Java类型 。
public Response getImage(@PathParam("imageId") Long imageId) throws IOException{
...
return Response.ok( image, mediatype).build();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.