react-native-fetch-blob icon indicating copy to clipboard operation
react-native-fetch-blob copied to clipboard

Failed to open file on IOS / Android is just fine

Open berkankisaoglu opened this issue 7 years ago • 1 comments

Hey there --

I am having trouble opening a file on IOS. The following code results with an error Error: The file “E7BD182B-89ED-4929-960B-067297D1936E-11811-00021674B2B235F4.jpg” couldn’t be opened. but it just works fine on android.

    this.camera.capture({metadata: {}})
        .then((data) => {
          console.log(`photo saved at path ${data.path}`)
          RNFetchBlob.fs.exists(data.path).then((exists) => {
            if (exists) {
              console.log(`file exists in the path, will try to get the stats`)
              RNFetchBlob.fs.lstat(data.path).then((stats) => {
                console.log(`stats success`)
                console.log(stats)
              }).catch((err) => {
                console.log(`error fetching stats`)
                console.log(err)
              })
            } else {
              console.log(`file doesn't exist`)
            }
          }).catch((err) => {
            console.log(`error checking if file exists`)
            console.log(err)
          })
        }).catch(err => console.error(err));

Console output on android devices are like --

photo saved at path file:///data/user/0/com.awesomeapp/cache/IMG_20180208_083552864952174.jpg
file exists in the path, will try to get the stats
stats success
[{…}]

Console output on ios devices are like --

photo saved at path /Users/usergoeshere/Library/Developer/CoreSimulator/Devices/CE00F86A-2284-4FBC-95F1-B7343B3A1088/data/Containers/Data/Application/F959EAD6-EB17-4761-99EE-39A0C4EB35A8/tmp/E7BD182B-89ED-4929-960B-067297D1936E-11811-00021674B2B235F4.jpg
file exists in the path, will try to get the stats
error fetching stats
Error: The file “E7BD182B-89ED-4929-960B-067297D1936E-11811-00021674B2B235F4.jpg” couldn’t be opened.
    at fs.js:267
    at MessageQueue.__invokeCallback (MessageQueue.js:347)

Could you point me in the right direction to make it work on iOS as well? I am "react-native": "0.50.4" and "react-native-fetch-blob": "^0.10.8"

berkankisaoglu avatar Feb 08 '18 08:02 berkankisaoglu

@berkankisaoglu check that you are not using a RNFetchBlob "Android Only" feature.

In my case, my destination path was using RNFetchBlob.fs.dirs.PictureDir... that is Android Only.

By the way, this repo is obsolete, use the new one: https://github.com/joltup/react-native-fetch-blob

JulienMalige avatar Apr 28 '18 21:04 JulienMalige