Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get base64 of image in React Native

Tags:

I'm using react native image picker and image resizer to pick and then resize an image. How do I get the base64 of the image once it has been resized?

ImagePickerManager.showImagePicker(imagepicker_options, (response) => {
  ImageResizer.createResizedImage(response.uri, 550, null, 'JPEG', 100).then((resizedImageUri) => {
    //get base64 of image
  });
});
like image 449
Wern Ancheta Avatar asked May 08 '16 11:05

Wern Ancheta


People also ask

What is Base64 image?

Base64 encoding is a way to encode binary data in ASCII text. It's primarily used to store or transfer images, audio files, and other media online. It is also often used when there are limitations on the characters that can be used in a filename for various reasons.

How do I share an image in react native?

... import Share from 'react-native-share'; const App = () => { ... const shareImage = async () => { try { // capture component const uri = await captureRef(viewRef, { format: 'png', quality: 0.8, }); // share const shareResponse = await Share. open({url: uri}); } catch (error) { console.


1 Answers

https://libraries.io/npm/react-native-asset-library-to-base64

ImagePickerManager.showImagePicker(imagepicker_options, (response) => {
  ImageResizer.createResizedImage(response.uri, 550, null, 'JPEG', 100).then((resizedImageUri) => {
      //get base64 of image, uri is link to asset-library://
      ReadImageData.readImage(uri, (imageBase64) => {
    console.log(imageBase64);
    });
  });
});

you might also want to read this if you haven't https://github.com/facebook/react-native/issues/1158

like image 91
Aaron Saunders Avatar answered Sep 28 '22 03:09

Aaron Saunders