react-native-image-base64
react-native-image-base64 copied to clipboard
return wrong base64 string on android
Platform: android RN: 0.60.4
ImgToBase64.getBase64String("file:///data/user/0/com.myapp/cache/1581517067881.JPEG")
return wrong base64 string.
Hi @maxweb4u, Basically it returns the image base64 with adding (line breaks i.e. \n) implicitly. So that it differs with the actual base64 and you thought it is returning wrong base64.
So, I have work arround and finds the solution to removes the line breaks from it.
e.g: let resizedImgBase64 = await ImgToBase64.getBase64String(resizedImg.uri) resizedImgBase64 = resizedImgBase64.replace(/\n/gi, "");
We are using replace method of javascript here for removing \n's from base64 string. We are replacing all the \n with empty character "".
Hope it works for you.
Thanks
RNImgToBase64Module.java private String bitmapToBase64(Bitmap bitmap) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); return Base64.encodeToString(byteArray, Base64.DEFAULT); } we need to change Base64.DEFAULT to Base64.NO_WRAP