In my server side i have an image that will be sended via rest to the client side After sending, the image should be deleted.
So the image will be coppied on a fileoutputstream and i send the fileoutputstream to the client side and i delete the image.
i use the following code:
@GET
@Path("/get_image")
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public Response getImage(){
.......
File image = new File("myimage.png");
FileOutputStream oos = new FileOutputStream("imageToSend.png");
byte[] buf = new byte[8192];
InputStream is = new FileInputStream(image);
int c = 0;
while ((c = is.read(buf, 0, buf.length)) > 0) {
oos.write(buf, 0, c);
oos.flush();
}
ResponseBuilder response = Response.ok(oos);
response.header("Content-Disposition",
"attachment; filename=image.png");
oos.close();
is.close();
image.delete();
return response.build();
}
}
but when i execute the getImage method i found this error
org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: java.io.FileOutputStream of media type: application/octet-stream
at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:67)
at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:411)
If any one have idea about the cause of this problem....
kind regards