0

I'm using react-native-crop-image-picker to select an image on mobile. Once I have the image I save the image path - 'file:///Users/.../image-name.png'.

I need to send this image to a socket connection in base64 format. But I'm not sure how to do this. The crop-image-picker has an option to obtain the base64 string while selecting the image but due to memory constraints I can't save that and have to convert it on the go.

Zephyr
  • 1,612
  • 2
  • 13
  • 37
  • Does this answer your question? [How can I convert an image into Base64 string using JavaScript?](https://stackoverflow.com/questions/6150289/how-can-i-convert-an-image-into-base64-string-using-javascript) – poPaTheGuru May 18 '21 at 06:40
  • No I don't think I can use regular html elements like in react native – Zephyr May 18 '21 at 06:47

1 Answers1

0

have you tried https://github.com/Snapp-FidMe/react-native-image-base64 ?

import ImgToBase64 from 'react-native-image-base64';
     
ImgToBase64.getBase64String('file://youfileurl')
.then(base64String => doSomethingWith(base64String))
.catch(err => doSomethingWith(err));
Václav Ryska
  • 215
  • 2
  • 7