java - 剩余图像字节数

标签 java jakarta-ee rest

我已将图像存储在数据库中,我希望它通过休息公开。最好的方法是什么?

@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/

相关文章:

python - python 3 中的 REST Web 服务?

c# - WCF web服务和getJSON为跨域调用返回空数据

java - 添加自定义过滤器 Apache Shiro + Spring Boot

java - Logback 创建日志文件但不写入任何内容

java - Jboss 7.0.1 : Started 122 of 176 services (54 services are passive or on-demand)

java - 学习Java EE、jboss等

maven - 如何使用 Netbeans 7.3.1 + JBoss AS7 部署 WAR

java - 重试模式与休息客户端中的回退模式

java - 这个说法在java中正确吗?

java - 如何从 Play Framework 中的结果中获取状态代码