I am sending byte[] as encoded string through Android app. They way I am converting my byte[] is as follows (Basically byte[] is the thumbscan/fingerscan image): Android
byte[] imageData = m_left_enrollment_fmd(); // returns byte[] which is OK!
// Base64 belongs to android.util package
String forJson = Base64.encodeToString(imageData , Base64.DEFAULT);
And this is how I am decoding it on Server side (Java):
// Base64 belongs to java.util package
byte[] imageData = Base64.getDecoder().decode(sqlJsonParams.optString("IMAGE_DATA"));
It generates following exception:
]] Root cause of ServletException. java.lang.IllegalArgumentException: Illegal base64 character -1 at java.util.Base64$Decoder.decode0(Base64.java:714) at java.util.Base64$Decoder.decode(Base64.java:526) at java.util.Base64$Decoder.decode(Base64.java:549) at org.skm.webresources.mobilehis.v2.Fingerprint.getByteArray(Fingerprint.java:470) at org.skm.webresources.mobilehis.v2.Fingerprint.postFingerprint(Fingerprint.java:86) Truncated. see log file for complete stacktrace
- Question 1: What I am doing wrong?
- Question 2: Is it the correct way to send byte[] in REST Service?
The Q&A I have seen so far are as follows: