Getting local file in iOS using native response

I am trying to capture an audio file that has been saved locally and uploaded using firebase. I tried using react-native-fetch-blobas follows:

import RNFetchBlob from 'react-native-fetch-blob'

const fs = RNFetchBlob.fs

but I get an error:

Error: file not exists

Despite the fact that I use the same path, I return after saving the file. Therefore, I have:

console.log('Full path is ' + fullPath) // Gives /var/mobile/Containers/Data/Application/2446[...]E1A9/Documents/myfile.mp4

but then I'm trying

fs.readFile(RNFetchBlob.wrap(fullPath), 'base64').then((data) => ...

I get a "file does not exist" error.

Does anyone have an example of code for reading a (binary) file as a blob and using it, especially for uploading to firebase storage? All the examples I found capture a file from an external URL.

+4
source share
1 answer

iOS . , iOS, dir concat.

// fileUri is a string like "file:///var/mobile/Containers/Data/Application/9B754FAA-2588-4FEC-B0F7-6D890B7B4681/Documents/filename"
if (Platform.OS === 'ios') {
  let arr = fileUri.split('/')
  const dirs = RNFetchBlob.fs.dirs
  filePath = `${dirs.DocumentDir}/${arr[arr.length - 1]}`
} else {
  filePath = audioDataUri
}
0

Source: https://habr.com/ru/post/1676945/


All Articles