tags:

views:

20

answers:

1

hi, 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
 }

}
+1  A: 

You need a Response created by the builder method.

See Representations and Java types.

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

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