Read binary file as base64
complete
W
Wang Riwu
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
Evan Bacon
complete
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
Martin Mašek
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.
Cristi
Martin Mašek: how would you go about unziping on the phone?
Martin Mašek
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
Why not decode/encode in javascript?
W
Wang Riwu
Ron Arts: What do you mean? How do you read the file content in the first place?
Ron Arts
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?
W
Wang Riwu
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.
Ron Arts
Wang Riwu: > Also, since you can encode to base64 from js, why put that functionality in the library?
Why put features in the library, if it's available in javascript itself? Frankly I think the developers have too much on their plate already.
W
Wang Riwu
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?
Ron Arts
Wang Riwu: Couldn't you use Expo.FileSystem.readAsStringAsync(fileUri) for that? And use atob() for base64 encoding?
W
Wang Riwu
Ron Arts: No.
readAsStringAsync
throws could not be read
error if the file is binary (eg. .wav
). It's only meant for reading text file.Ron Arts
Wang Riwu: If only you'd mentioned that in the feature request.... You have my vote.