How to return a PNG image from Jersey REST service method to the browser

前端 未结 4 1891
粉色の甜心
粉色の甜心 2020-11-30 19:46

I have a web server running with Jersey REST resources up and I wonder how to get an image/png reference for the browsers img tag; after submitting a Form or getting an Ajax

4条回答
  •  萌比男神i
    2020-11-30 20:07

    in regard of answer from @Perception, its true to be very memory-consuming when working with byte arrays, but you could also simply write back into the outputstream

    @Path("/picture")
    public class ProfilePicture {
      @GET
      @Path("/thumbnail")
      @Produces("image/png")
      public StreamingOutput getThumbNail() {
        return new StreamingOutput() {
          @Override
          public void write(OutputStream os) throws IOException, WebApplicationException {
            //... read your stream and write into os
          }
        };
      }
    }
    

提交回复
热议问题