react-native-fs库没有移动或复制文件-奇怪的结果

问题描述

  npmPackages:
    @react-native-community/cli: ^4.13.0 => 4.13.0
    react: 16.13.1 => 16.13.1
    react-native: 0.63.3 => 0.63.3
    react-native-windows: Not Found
    react-native-fs: ^2.16.6
    react-native-image-picker: ^2.3.4
  IDEs:
    Android Studio: Version  3.6.0.0 AI-192.7142.36.36.6241897
    Visual Studio: 15.3.26730.12 (Visual Studio Community 2017)

我一直在尝试实现一个按钮,用于打开相机,拍摄图片并将其保存到图片文件夹。

为此,我正在使用:

是后者让我头疼。 这是我正在使用的代码:

<Buttons.Camera containerStyle={{marginBottom:5}}
  onPress={() => {
    ImagePicker.launchCamera(options,async (response) => {
      console.log('Response = ',response);

      if (response.didCancel) {
        // ToDo cancelled
        console.log('Cancellen');
      } else if (response.error) {
        console.log('Camera Error: ',response.error);
      } else {
        var RNFS = require('react-native-fs');
        const ext = response.fileName?.split('.').pop();
        let newPath = `${RNFS.PicturesDirectoryPath}/${options.storageOptions.path}/avatar.${ext}`;
        const result = await RNFS.moveFile(response.path,newPath);
        this.setState({
          avatarPath: newPath,});
      }
    });
  }} />

const result = await RNFS.moveFile(response.path,newPath);上命中了一个断点。我可以确认该图片确实存在于我的galary中,并且newPathresponse.path均有效。 当我尝试移动文件时(实际上是重命名),我注意到newPath处没有图像,response.path处的原始图像似乎已损坏,无法再打开。

根据文档,result应该是true,但在我的情况下是undefined。 当我使用RNFS.exists(newPath)时,也会发生同样的情况。诺言得以解决,但结果是undefined。没有错误抛出。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...