使用react-native-fs移动文件时,文件已经存在
我正在尝试使用iOS中的react-native-fs将图像移至库中,
const originalPath = "/private/var/mobile/Containers/Data/Application/7EB7B0CB-FCA8-49EE-843A-04BBB0B286B1/tmp/ReactNative/E70143FD-21A8-42AA-BFD2-A8FA45D7D93A.png"
const destinationPath = RNFS.LibraryDirectoryPath + "/kj3.jpg";
RNFS.moveFile(screenShotPath, destinationPath).then((data) => {
console.log(data)
}).catch((err) => {
throw err
})
在这种情况下,目的地路径是
/var/mobile/Containers/Data/Application/7EB7B0CB-FCA8-49EE-843A-04BBB0B286B1/Library/kj3.jpg
我遇到一个错误,
Error: “E70143FD-21A8-42AA-BFD2-A8FA45D7D93A.png” couldn’t be moved to “Library” because an item with the same name already exists.
当我尝试复制文件时,我也会遇到相同的错误。
I am trying to move an image to the library using react-native-fs in iOS
const originalPath = "/private/var/mobile/Containers/Data/Application/7EB7B0CB-FCA8-49EE-843A-04BBB0B286B1/tmp/ReactNative/E70143FD-21A8-42AA-BFD2-A8FA45D7D93A.png"
const destinationPath = RNFS.LibraryDirectoryPath + "/kj3.jpg";
RNFS.moveFile(screenShotPath, destinationPath).then((data) => {
console.log(data)
}).catch((err) => {
throw err
})
The destination path in this case is
/var/mobile/Containers/Data/Application/7EB7B0CB-FCA8-49EE-843A-04BBB0B286B1/Library/kj3.jpg
I get an error
Error: “E70143FD-21A8-42AA-BFD2-A8FA45D7D93A.png” couldn’t be moved to “Library” because an item with the same name already exists.
I also get the same error when I try to copy the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在iOS中,如果已经存在,则不会覆盖图像。请尝试安装屏幕截图和目标路径,以确保路径确实不同。
以下是一个工作解决方案,您可以首先检查文件是否存在。如果是这样,它将尝试先删除它,然后在您要防止存在错误时移动文件。
希望它能帮助您!
In iOS, image will not overwrite if already exists. Please try to console.log the screenShotPath and destinationPath to make sure the path are really different.
Below is a working solution shows that you can first check the file is it exists. If so, it will try to remove it first, then it will move the file as you want to prevent any exists error.
Hope it will help you!