I have a spring boot application deployed on a tomcat that's make me able to upload images from and android application. Now I'm trying to get that images. The problem is that my endpoint of my controller returns a FileSystemResource and I don't know how to handle it.
Endpoint:
@GetMapping(value = "/getFotoPerfil", produces = MediaType.IMAGE_JPEG_VALUE)
public FileSystemResource getFotoPerfil(@RequestParam("path") String path) {
return utilitiesService.findInFileSystem(path);
}
The response I receive:
If I make the call with Postman, it works:
Any help will be appreciated
CodePudding user response:
Your problem is that your client code seems to be assuming that it will be getting JSON. The controller is returning an image (although it's a PNG, even though you're inaccurately telling the client it's image/jpeg
), which is binary data. In Java, this response should normally be handled as a byte[]
instead of a String
.