Oli*_*via 6 react-native react-native-fs react-native-ios
我正在尝试使用react-native-fs和react-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.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
仅供参考,我正在使用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);
});
}
Run Code Online (Sandbox Code Playgroud)
我相信我已经找到了错误。问题是我上传的文件中有一个空格。我需要在上传之前先解码 URL,如下所示:
var decodedURL = decodeURIComponent(url)
然后我就可以把文件移过来。
RNFS.copyFile(decodedURL, destPath)
| 归档时间: |
|
| 查看次数: |
6729 次 |
| 最近记录: |