Skip to main content

jersy restful get image

1 reply [Last post]
khanq
Offline
Joined: 2009-11-27
Points: 0

Hi at all.

I want to return an image by using rest (jersey).
I thought it would be something like this:

@Path("test.png")
@GET
@Produces("image/png")
public Response getViewImage() throws Exception{
File file = new File("test.png");
return Response.ok(file).build();
}

But it seems to be not that simple.
I tried to return a stream ... but this did not work either.
I could return a url, but in fact this needs a extra webserver and I want to do this only with jersey.

Someone has an idea?
Google did not help ...oddly enough.

mfg KhanQ

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
khanq
Offline
Joined: 2009-11-27
Points: 0

Ok, the above code was correct.
I only changed the file location to a absolute path and it works fine.

Maybe this helps someone else.

@Path("test.png")
@GET
@Produces("image/png")
public Response getViewImage() throws Exception{
File file = new File("/home/test/test.png");
return Response.ok(file).build();
}