Read binary file as base64
Add functionality to FileSystem to allow reading binary files as base64 encoding.
Example use case:
Read recorded audio files and send to external API as base64: https://cloud.google.com/speech/reference/rest/v1/RecognitionAudio
marked this post as
v31 has this now as part of FileSystem https://docs.expo.io/versions/v31.0.0/sdk/filesystem#expofilesystemreadasstringasyncfileuri-options
Here is an example: https://snack.expo.io/@bacon/audio-to-base64
This would be useful for me as well. My use case is downloading a zip from server, unzipping it on the phone and saving images.
Martin Mašek: how would you go about unziping on the phone?
Cristi: I think there must be a library for it but I got rid of the use case mentioned in this thread for now.
Ron Arts: What do you mean? How do you read the file content in the first place?
Wang Riwu: According to the docs recordingInstance.getURI() returns the local URI of the recording, so it would seem you could read it. Also, since you can encode to base64 from js, why put that functionality in the library?
Ron Arts: > so it would seem you could read it
There's no functionality in the FileSystem module to read a URI resource as base64. That's what this request is about.
Wang Riwu: > Also, since you can encode to base64 from js, why put that functionality in the library?
Ron Arts: Encode what to base64? There's no functionality to read the URI resource in binary. How do you encode a URI resource without reading it first?
Wang Riwu: Couldn't you use Expo.FileSystem.readAsStringAsync(fileUri) for that? And use atob() for base64 encoding?
Ron Arts: No.
could not be readerror if the file is binary (eg.
.wav). It's only meant for reading text file.
Wang Riwu: If only you'd mentioned that in the feature request.... You have my vote.