question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Following this, i’m trying to get the content file;

Using react-native-document-picker, after select the file I do this:

if (Platform.OS === 'ios') {
    let arr = data.uri.split('/')
    const dirs = RNFetchBlob.fs.dirs
    filename = RNFetchBlob.wrap(`${dirs.DocumentDir}/${arr[arr.length - 1]}`)
} else {
    filename = data.uri
}
const file = await RNFetchBlob.fs.readFile(filename, 'base64')

I also tried:

// filename = RNFetchBlob.wrap(data.uri)
// filename = data.uri

But I always get the same error file not exists

This is the data from react-native-document-picker:

{
  "size": 16669,
  "name": "Imagem JPEG.jpeg",
  "uri": "file:///private/var/mobile/Containers/Data/Application/63F987D9-81F6-41B1-80A1-8E9E102C82FD/tmp/br.com.app-Inbox/Imagem%20JPEG.jpeg",
  "type": "image/jpeg"
}

What could I be missing?

"react": "16.0.0-alpha.12"
"react-native": "^0.48.4"
"rn-fetch-blob": "^0.10.11"
"react-native-document-picker": "git://github.com/Elyx0/react-native-document-picker.git#v3",

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11

github_iconTop GitHub Comments

98reactions
rochapablocommented, Jul 16, 2018

Wait!!!

Just using filename = data.uri.replace('file:', '') as @andonivianez said here, did work!

The final code:

if (Platform.OS === 'ios') {
      filename = data.uri.replace('file:', '')
} else {
      filename = data.uri
}

I’m going grab a beer, closing for now!

2reactions
SandeepKharbandacommented, Aug 19, 2021

I have tried it with the below way and After that, It’s working fine.

  let documentURI = doc.uri;
  if (Platform.OS === 'ios' ) {
    documentURI = decodeURIComponent(documentURI.replace('file://', ''));
  }
  
  await RNFetchBlob.fs.readFile(documentURI, 'base64');

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to check if file does not exist in Bash - nixCraft
-f filename ( test -f filename ) returns true if file exists and is a regular file. The ! (exclamation point) act as...
Read more >
How do I tell if a file does not exist in Bash? - Stack Overflow
Negate the exit status with bash (no other answer has said this): if ! [ -e "$file" ]; then echo "file does not...
Read more >
How To Check If File or Directory Exists in Bash - devconnected
In order to check if a file does not exist using Bash, you have to use the “!” symbol followed by the “-f”...
Read more >
Bash Check If File Not Exists - Linux Hint
To check for the file exists or not, we will be using the “If-then” statement taking its conditions in the single square brackets...
Read more >
Bash: How to Check if the File Does Not Exist - DiskInternals
Bash: how to check if the file does not exist? Here you will find the way of how to check if the file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found