React-native-fs: 馃敟 Bug: path.startsWith is not a function

Created on 6 Jul 2019  路  3Comments  路  Source: itinance/react-native-fs

Issue:
path.startsWith is not a function at normalizeFilePath (FS.common.js:28) at Object.copyFile (FS.common.js:200) at BackgroundSettingsComponent.js:243 at tryCallOne (core.js:37) at core.js:123 at JSTimers.js:298 at _callTimer (JSTimers.js:152) at _callImmediatesPass (JSTimers.js:200) at Object.callImmediates (JSTimers.js:473) at MessageQueue.__callImmediates (MessageQueue.js:337)

Code:

````
onUploadCustomPhoto() {
ImagePicker.openPicker({ multiple: false })
.then(image => {
console.log('image.path', image.path)
ImagePicker.openCropper({
path: image.path,
width: width,
height: height,
})
.then(editedImage => {
let editedImagePath = editedImage.path;
let date = new Date();
let timestamp = Math.floor(date.getTime() + date.getSeconds())
const pathToImage = RNFS.DocumentDirectoryPath}/mood-pixel-background-time${timestamp}.jpg;

    console.log('editedImagePath', editedImagePath, typeof editedImagePath)

    try {
      RNFS.copyFile({
        filePath: editedImagePath, //Platform.OS === 'ios' ? `file://${editedImagePath}` : `${editedImagePath}`,
        destPath: pathToImage,
      }).then(response => {
        console.log('response', response)
      })
      } catch (error) {
       console.log('error in trycatch', error)
     }
  })
})

}
````

Console:
Screenshot 2019-07-06 at 16 46 09

Any ideas why this might be happening?
I am using this package to download images from a server and it works perfectly. However, .copyFile is not working.

"react": "16.8.3", "react-native": "0.59.8", "react-native-fs": "^2.13.3", "react-native-image-crop-picker": "^0.24.1",

Most helpful comment

The error path.startsWith is not a function is raised when you pass a non String type, to copyFile(), for example an Object.
In my case I was passing in a Promise - I'm still kicking myself. String.startsWith docs

All 3 comments

My bad.

RNFS.copyFile({ filePath: editedImagePath, //Platform.OS === 'ios' ? `file://${editedImagePath}` : `${editedImagePath}`, destPath: pathToImage, })

It should be to parameters not an object.

i did not understand your hack

The error path.startsWith is not a function is raised when you pass a non String type, to copyFile(), for example an Object.
In my case I was passing in a Promise - I'm still kicking myself. String.startsWith docs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

1556173267 picture 1556173267  路  3Comments

zaheerahmad92001 picture zaheerahmad92001  路  3Comments

CesarLanderos picture CesarLanderos  路  4Comments

opoze picture opoze  路  3Comments

PimDeWitte picture PimDeWitte  路  4Comments