Writing non-text files to disk using Expo.FileSystem

Is it possible to write non-text files to disk using Expo.FileSystem, for example an image or video?

I want to store a base64 encoded image in Expo.FileSystem.cacheDirectory so that I can call CameraRoll.saveToCameraRoll on android against it. I would really prefer not having to eject my app (i.e. use react-native-fetch-blob) for this.

I have tried using Expo.FileSystem.downloadAsync with a data uri but this fails on android.

Has anyone accomplished this? Thanks!

1 Like

Same issue on android an expo 29.0

await FileSystem.downloadAsync(‘data:application/pdf;base64,somecontent’,FileSystem.cacheDirectory + “download.pdf”);

My error is:

[Unhandled promise rejection: Error: unexpected url: data:application/pdf;base64,JJSBropvEZ1QCYEY]

Stack trace:
node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:121:42 in createErrorFromErrorData
node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:78:57 in
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:398:4 in __invokeCallback
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:137:28 in
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:6 in __guardSafe
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:136:17 in invokeCallbackAndReturnFlushedQueue

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.