1
I am developing a mobile application that send photos of the application to the server, made in springboot. When receiving the request with the image, via json, I try to convert String to Image. However, in the conversion it returns null. For some reason the conversion is not happening and not saving the image.
@PostMapping(value = "/paciente")
public void paciente(@RequestBody String foto) throws IOException {
try {
byte[] encoded = Base64.encodeBase64(foto.getBytes());
System.out.println("Encoded retorna >" + encoded)
ByteArrayInputStream input = new ByteArrayInputStream(encoded);
System.out.println("URL retorna >" + input);
BufferedImage image = ImageIO.read(input);
System.out.println("IMAGE retorna >" + image);
ImageIO.write(image, "jpg", new File("C:/Users/carlo/Downloads/SisCAF/images/myImage1.jpg"));
System.out.println("image created");
} catch (Exception e) {
}
}
The exit: Encoded returns >[B@7646546e URL returns >java.io.Bytearrayinputstream@1b7a9dc1 IMAGE returns >null
pq you call this encodedBase64?
– Lucas Miranda
as far as I know this
Base64.encodeBase64
is turning this photo into Base64. tries to use like this:byte[] encoded = Base64.decode(foto);
– Walter Felipe