Dynamically create image from JAX-RS servlet

前端 未结 1 502
傲寒
傲寒 2021-01-13 20:26

Is it possible to create a PNG image and output it straight to the browser as part of a JAX-RS resource?

Something like this:

@Path(\"img/{externalId         


        
相关标签:
1条回答
  • 2021-01-13 20:51

    Take a look at http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e323:

     @GET
     @Path("/images/{image}")
     @Produces("image/*")
     public Response getImage(@PathParam("image") String image) {
         File f = new File(image);
    
         if (!f.exists()) {
             throw new WebApplicationException(404);
         }
    
         String mt = new MimetypesFileTypeMap().getContentType(f);
         return Response.ok(f, mt).build();
     }
    
    0 讨论(0)
提交回复
热议问题