2010-08-22 3 views
1

나는 이미지를 데이터베이스에 저장했으며 나머지는 노출시키고 싶다. 가장 좋은 방법은 무엇입니까?rest-to-image-bytes

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

} 

답변

1

작성자 메소드로 작성된 응답이 필요합니다.

Representations and Java types을 참조하십시오.

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

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