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

base64 string got from ImageEditor.cropImage(uri) have linefeed after each 76 characters. #11142

Closed
linus87 opened this issue Nov 26, 2016 · 4 comments
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot.

Comments

@linus87
Copy link

linus87 commented Nov 26, 2016

Description

I launched "react-native run-android" on MAC 10.11.6 (15G1004). I found when I use ImageEditor.cropImage(uri) to crop an image, the base64 text of image is not as my expected. Base64 text of image should be a whole string. But I found there is a linefeed after each 76 characters. When I put it as a JOSN object value, and stringify the JSON object. Then I try to parse this JSON object. I will meet a error: Unexpected Token. If I use base64Text.replace("\n", "").replace("\r",""), then It's ok;

for example:
ImageStore.getBase64ForTag(url, (base64Data) => {
let sImageBase64Data = "data:image/jpg;base64," + base64Data.replace(/\n|\r/g, "");
}

Solution

Replace all linefeed and carriage-return by base64Data.replace(/\n|\r/g, "").

Additional Information

  • React Native version: 0.29
  • Platform: Android
  • Operating System: MacOS
@mkonicek
Copy link
Contributor

Good find, thanks for reporting it! Note that RN releases older than latest are not supported, can you try if the bug is still present in the latest release? Would you be up for fixing it here?
https://github.com/facebook/react-native/blob/9ee815f6b52e0c2417c04e5a05e1e31df26daed2/ReactAndroid/src/main/java/com/facebook/react/modules/camera/ImageStoreManager.java

Found this: http://stackoverflow.com/questions/19952621/is-it-ok-to-remove-newline-in-base64-encoding

@mkonicek mkonicek added Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. labels Nov 27, 2016
leeight added a commit to leeight/react-native that referenced this issue Nov 27, 2016
@joshjhargreaves
Copy link
Contributor

joshjhargreaves commented Nov 28, 2016

Yeah I don't mind taking a look.
Actually looks like it might already be addressed.

@wellmonge
Copy link
Contributor

@leeight seems the issue has been solved on #11155 !?

@hramos
Copy link
Contributor

hramos commented May 25, 2017

Closing this issue because it has been inactive for a while. If you think it should still be opened let us know why.

@hramos hramos closed this as completed May 25, 2017
@hramos hramos added the Icebox label May 26, 2017
FnTm added a commit to FnTm/react-native that referenced this issue Sep 6, 2017
facebook-github-bot pushed a commit that referenced this issue Oct 10, 2017
Summary:
FIX #11142

This fixes #11142 and supersedes #11155 as I was unsure how to add/change commits in that PR.

Wrote up a bunch of unit tests for the ImageStore module. The added tests showed that there was indeed a problem with the flags used for the Base64OutputStream, and they also show that that has been fixed now.
Closes #13856

Differential Revision: D6017764

Pulled By: shergin

fbshipit-source-id: adf667dc722ddfe31449afd8cd20a0a192eacff6
@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot.
Projects
None yet
6 participants