I'm trying to move a file selected from a document picker to the Document Directory using react-native-fs and react-native-document picker.
However, I get the error below:
Error: “file name.mp3” couldn’t be moved to “Documents” because either the former doesn't exist, or the folder containing the latter doesn't exist.
What am I doing wrong?
FYI, I'm using iOS.
openDocumentPicker() {
  DocumentPicker.show({
    filetype: ['public.audio'],
  },(error,url) => {
    console.log(url);
    this.saveAudio(url);
  });
}
saveAudio(url) {
  var destPath = RNFS.DocumentDirectoryPath + '/' + 'name';
  RNFS.moveFile(url, destPath)
    .then((success) => {
      console.log('file moved!');
    })
    .catch((err) => {
      console.log("Error: " + err.message);
    });
}
                I believe I've found the error. The issue was that the file I was uploading had a space in it. I needed to decode the URL first before uploading, like so:
var decodedURL = decodeURIComponent(url)
Then I could move the file over.
RNFS.copyFile(decodedURL, destPath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With