我已将图像存储在数据库中,我希望它通过休息公开。最好的方法是什么?
@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
}
}
最佳答案
您需要由构建器方法创建的响应。
参见Representations and Java types .
public Response getImage(@PathParam("imageId") Long imageId) throws IOException{
...
return Response.ok( image, mediatype).build();
}
关于java - 剩余图像字节数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3539844/