I have been trying many ways to read a binary file and convert it to base64 in order to send jpg images from the iPhone and Androids to an internal web-service.
However, after upgrading to Expo 31 this broke with different errors on Android and iOS. Androids was a Network Error. iOS “works” but no data is returned. I am trying now to make it work with Expo 32.
I have tried the solution priezz suggested. This works on Android, but I get an error on iOS fileToBase64() "File '<filepath>' could not be read."
When will we have an Expo Blessed way to read arbitrary files off of the FileSystem.
Ensure, that you pass the correct URI to the fileToBase64Helper/fileToBase64 function. On iOS you have to pass unescape(uri) while od Android just uri you have got from Expo file routine.
fileToBase64(), File 'file:///var/mobile/Containers/Data/Application/60DB7C82-31AE-406F-BEFD-88D7C5FFC08A/Documents/ExponentExperienceData/%2540kbloom-autologue%252Fautologue-edelivery-app/signatures/d541d7cd7bc704d67c4087c8c8960492.jpg' could not be read.
finally if I apply it twice unescape(unescape(uri))
Ok, I solved the problem. Turns out all of this can be replaced with the new options for readAsStringAsync
The issue is the documentation has a minor typo (that started my whole confusion). The three parameters encoding, length, and position are part of the options property not separate positional parameters. so all of that Base64 converting code can be replaced with