Problems with axes, Spring Boot and base64

0

I'm trying to make a post from my react native app for my Spring boot application. However, I'm getting this error:

  

java.lang.IllegalArgumentException: Illegal base64 character a

React Native Code:

axios({
    method: 'post',
    url: 'myip',
    data: {
        teste: photo.image.base64,
    },
    headers: {'content-type': 'application/json'},
}) 
.then(function (response) {
    console.log("works");
})
.catch(function (error) {
    console.log(error);
});

Spring Boot Code

@RequestMapping(value = "/", method = RequestMethod.POST)
public Map<String, String> upload (@RequestBody Map<String, String> payload) {
    byte[] imageByte;
    String encodedString = payload.get("teste");
    String fileName = (new Date()).toString();
    fileName = fileName.replace(' ', '_');
    fileName = fileName.replace(':', '_');

    try {
        imageByte = Base64.getDecoder().decode(encodedString.toString());
        FileUtils.writeByteArrayToFile(new File(fileName + ".png"), imageByte);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("error");
    }
    return response;
}

I can not see what's missing. Many thanks for the help!

    
asked by anonymous 20.12.2018 / 12:22

0 answers