Image to base64 using JavaScript in native app

0
Hi Experts, I’m currently trying to implement OCR in my native mobile app where I need to convert my image file to base64 using JavaScript. How to convert image to base64 using js? How to retrieve the image from imendix object in the js code?  
asked
4 answers
0

Have a look at: https://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript to get an idea for the javascript base64 encoding/decoding

[Update]

For image to base64 see: https://stackoverflow.com/questions/6150289/how-can-i-convert-an-image-into-base64-string-using-javascript

answered
0

Hi Vignes,

The JavaScript engine in the Native React client is JavaScript Core https://reactnative.dev/docs/javascript-environment (a Fun fact, when debugging the environment is the v8 of your browser, this explains way it might work while debugging but on on the device)

This JsCore does not support the same function as v8 on the web. So there is no easy way to convert a file to base 64 in both directions. 

Google around and you might get somewhere. But it always requires an additional module.... https://stackoverflow.com/questions/34908009/react-native-convert-image-url-to-base64-string

So if you got one working let us know! I would love to see a simpler solution.

Cheers, 

Andries

answered
0

+1

Vignesh S, did you figure it out? I have the same problem. :\

answered
0
const fileUrl = mx.data.getDocumentUrl(file.getGuid(), file.get("changedDate"));
let base64 = await NativeModules.NativeFsModule.readAsDataURL(fileUrl);

Worked for me if you have your document as MxObejct.

answered