【问题标题】:Move file from tmp to documents using react-native-fs使用 react-native-fs 将文件从 tmp 移动到文档
【发布时间】:2017-06-05 21:19:32
【问题描述】:

我正在尝试使用 react-native-fsreact-native-document picker 将从文档选择器中选择的文件移动到文档目录。

但是,我收到以下错误:

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.

我做错了什么?

仅供参考,我使用的是 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);
    });
}

【问题讨论】:

    标签: react-native react-native-ios react-native-fs


    【解决方案1】:

    我相信我发现了错误。问题是我上传的文件中有一个空格。我需要在上传之前先对 URL 进行解码,如下所示:

    var decodedURL = decodeURIComponent(url)

    然后我可以移动文件。

    RNFS.copyFile(decodedURL, destPath)

    【讨论】:

      【解决方案2】:

      当目标文件夹不存在时发生在我身上。

      [tid:com.facebook.react.JavaScript] 'error!', { [Error: The file “source.jpg” doesn’t exist.]
      

      这是来自react-native-fs 的错误消息。它应该告诉目标路径文件夹不存在

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-28
        • 2015-11-06
        • 2017-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多