簡體   English   中英

剩余圖像字節

[英]image-bytes to 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
 }

}

您需要使用builder方法創建的Response。

請參見制圖表達和Java類型

public Response getImage(@PathParam("imageId") Long imageId) throws IOException{

    ...
    return Response.ok( image, mediatype).build();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM