Cannot get an image from inputStream

230 Views Asked by At

First thing, I'm new in jee and rest services, I'm developing an application in java that receive an image from a client and stores it in a glassfish db. Then it can be returned. I´m having a problem gettin the image from the input stream, I tried ImageIO.read(inputStream) like seeing in many questions here, but it´s allways return null. And if I convert it to bytes, save it, recoverted to image file from the bytes the image its shown corrupted. Aparently im saving rubish with the image when i convert that way the inputStream.

How can I extract the image correctly from the inputStream? There is another way to send it?

I´m posting the image in this way

Code from the app side:

     BufferedImage image = ImageIO.read(imagen);

     @POST
     @Path("subir/{usuario}/{nombreImagen}")
     public Response obtenerImagen(@PathParam("usuario") String usuario,
                                   @PathParam("nombreImagen") String nombreImagen,
                                   InputStream imagen) throws IOException {
         BufferedImage image = ImageIO.read(imagen);
         ...
0

There are 0 best solutions below