[ACCEPTED]-How to return image as stream from JAX-RS?-jackson

Accepted answer
Score: 25

Just use StreamingOutput wrapper. For some reason it is 2 unknown, but it is GREAT for providing, well, streaming 1 output. :-)

Score: 9

I think you need to provide an InputStream 12 containing the image in the Response.ok(out) not 11 an OutputStream. (Your JAX-RS framework 10 would read the bytes from the InputStream 9 and put them onto the response, it wouldn't 8 be able to do anything generically with 7 an OutputStream)

(I know you're on CXF, but 6 Jersey's doc: http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e324 and by the JAX-RS spec, the 5 framework must provide a MessageBodyWriter 4 for InputStream.)

Edit: You apparently know 3 about InputStreams being required, d'oh... Do 2 you have control over the QRCode class?

Short 1 term, you might be able to do:

return Response.ok(out.toByteArray()).build();

More Related questions