question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImagePicker android returns invalid base64 string with line breaks

See original GitHub issue

Hello guys!

I got a problem with the ImagePicker and the base64 option.

This is the code :

ImagePicker.launchImageLibraryAsync({mediaTypes: 'Images', allowsEditing: true, base64: true}) .then(source =>{console.log('source', source) if(!source.cancelled){ this.setState({source}) } });

When I use an Iphone (ios9 4S), the console log of the result is :

image

I can perfectly send this to my backend (I use Intervention with PHP) and everything is fine.

But with android, I got this :

image

We see the string is very different than the first one. And when I pass this to my backend, Intervention gives me an Exception “Image source not readable”.

I tried to process the base64 string result but with no success.

I repeat, everything is fine with IOS.

The base64 result of the ImagePicker is not good with android.

My problem came from only the base64 result.

Thanks for your answer!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
dlcardozocommented, Nov 6, 2018

Follow @aalices tip, just remove the new lines with something like:

base64image = base64image.replace(/(?:\r\n|\r|\n)/g, '');

4reactions
aalicescommented, Mar 14, 2018

I think it is a separate problem. Will this work if you remove new line symbols from the string?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading an image file from device storage and converting to ...
I'm trying to read file from a known path get base64 string from the image. I still don' ...
Read more >
Convert.ToBase64String Method (System) - Microsoft Learn
Converts the value of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits.
Read more >
ImagePicker - Expo Documentation
Represents an asset (image or video) returned by the image picker or camera. Name, Type, Description. assetId (optional), string | null ...
Read more >
base64_encode - Manual - PHP
Encodes the given string with base64. This encoding is designed to make binary data survive transport through transport layers that are not 8-bit...
Read more >
Data URLs - HTTP - MDN Web Docs - Mozilla
Base64 encoding of a file or string on Linux and macOS systems can be achieved using the command-line base64 (or, as an alternative, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found