Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return wrong base64 string on android #19

Open
maxweb4u opened this issue Feb 12, 2020 · 2 comments
Open

return wrong base64 string on android #19

maxweb4u opened this issue Feb 12, 2020 · 2 comments

Comments

@maxweb4u
Copy link

Platform: android
RN: 0.60.4

ImgToBase64.getBase64String("file:///data/user/0/com.myapp/cache/1581517067881.JPEG")

return wrong base64 string.

@shehzadosama
Copy link

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

@thinhvkit
Copy link

thinhvkit commented Jan 27, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants