How to send image in Restful Jax-rs

jax-rs

Solution

I believe that's because you specified `application/octet-stream`.

I think you should use `image/jpeg` or `image/png`.

@GET
@Produces({"image/png"})
public Response getUserImage() {

    final byte[] image = ...;
    // say your image is png?

    return Response.ok().entity(new StreamingOutput(){
        @Override
        public void write(OutputStream output)
           throws IOException, WebApplicationException {
           output.write(image);
           output.flush();
        }
    }).build();
}

Problem

I want to send an image from java server (Restful Jax-rs). My client is Android. ``` @GET public Response getUserImage() { byte[] image =new byte[1024]; return Response.ok(image, MediaType.APPLICATION_OCTET_STREAM).header("content-attachment; filename=image_from_server.png") .build(); ``` But here one download box is coming. So I want to download without download box, when I run the request URL on browser it should open automatically. Thanks.

Original source