2017-06-05 155 views
1

我試圖使用react-native-fsreact-native-document picker將從文檔選擇器選擇的文件移動到文檔目錄。將文件從tmp移動到使用react-native-f的文檔

不過,我得到以下錯誤:

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

回答

0

我相信我發現了這個錯誤。問題是我上傳的文件有一個空間。我需要的URL上傳之前先進行解碼,就像這樣:

var decodedURL = decodeURIComponent(url)

然後,我可以移動的文件了。

RNFS.copyFile(decodedURL, destPath)

0

它發生在我身上時,目標文件夾不存在。

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

這是從react-native-fs錯誤的錯誤消息。它應該告訴目標路徑文件夾不存在

相關問題