Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not exists #116

Closed
rochapablo opened this issue Jul 16, 2018 · 13 comments
Closed

File not exists #116

rochapablo opened this issue Jul 16, 2018 · 13 comments

Comments

@rochapablo
Copy link

rochapablo commented Jul 16, 2018

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",
@ihavenoface5
Copy link
Collaborator

Is the %20 in the filename intentional (Imagem%20JPEG.jpeg)? I think iOS would have a problem with this.

@rochapablo
Copy link
Author

I thought about that and rename the file, but it still cant find the file.

@dantman
Copy link

dantman commented Jul 16, 2018

Try using v3 and the fetch() built into React Native. The React Native FS and React Native Fetch Blob libraries are not supported.

@rochapablo
Copy link
Author

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!

@MikaelStenstrand
Copy link

Thanks @rochapablo for the tip! After getting the URI right with your suggested method, I had to still add the buffer.

yarn add buffer
and importing the buffer to the project
global.Buffer = global.Buffer || require("buffer").Buffer; // buffer needed for file reading
Then everything worked for me.

@karltaylor
Copy link

I still don't know why this is the correct way to read IOS urls in the docs. Took me ages.

@BatDroid
Copy link

BatDroid commented Apr 3, 2019

based on this for android i did this :

uri.split('raw%3A')[1].replace(/\%2F/gm, '/')

ios:

uri.replace("file://", "")

@mishuagopian
Copy link

Hey @rochapablo why did you add Buffer in order to work?

@SandeepKharbanda
Copy link

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');

@joramirezStackit
Copy link

I think I found the problem, in my case I had something like this "%20" (seems like an space) in the path I was using and I did something like this uri.replace('file://', '').replaceAll('%20', ' ') and it worked

@vhonLopez
Copy link

I think I found the problem, in my case I had something like this "%20" (seems like an space) in the path I was using and I did something like this uri.replace('file://', '').replaceAll('%20', ' ') and it worked

This one worked!!! saved my life.

@ehbasouri
Copy link

I think I found the problem, in my case I had something like this "%20" (seems like an space) in the path I was using and I did something like this uri.replace('file://', '').replaceAll('%20', ' ') and it worked

thanks, worked for me

@vinod1988
Copy link

Thanks this solutions work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests