I'm trying to return an image as a response in spring framework, it works just fine implementing like this:
@GetMapping(value = "/{photo}.{suf}")
public @ResponseBody byte[] getImage(@PathVariable("photo") String photo,@PathVariable("suf") String suf) throws IOException{
InputStream in = FileUtils.openInputStream(new File("src/main/resources/static/" + photo + "." +suf));
return IOUtils.toByteArray(in);
}
but when I try to return the image file inside a response object ,I get an org.springframework.web.HttpMediaTypeNotAcceptableException exception:
@GetMapping(value = "/{photo}.{suf}")
public @ResponseBody ResponseObject getImage(@PathVariable("photo") String photo,@PathVariable("suf") String suf) throws IOException{
InputStream in = FileUtils.openInputStream(new File("src/main/resources/static/" + photo + "." +suf));
return new ResponseObject(IOUtils.toByteArray(in),1);
}
here is my ResponseObject implementation:
public class ResponseObject {
private Object object;
private int status;
public ResponseObject(Object object,int status){
this.object = object;
this.status = status;
}
public Object getObject() {
return this.object;
}
public void setObject(Object object) {
this.object = object;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
Does anyone have any idea why this is happening?