无法通过react-native-fs删除照片

问题描述 投票:0回答:1

我使用react-native-camera拍照并通过CameraRoll将其保存到ios设备中。

这里是代码:

    import { CameraRoll } from 'react-native';
    import { RNCamera } from 'react-native-camera';

    // take the picture
    const data = await this.camera.takePictureAsync(options);
    // save it to state
    this.setState({ countdownFinish: true, path: data.uri });
    // and save it to my device's gallery
    CameraRoll.saveToCameraRoll(this.state.path);

data.uri是

file:///var/mobile/Containers/Data/Application/14E28AC2-5E35-4749-B09F-75DBEB0499A4/Library/Caches/Camera/6C6B1C9F-FDAF-4BEB-BEB0-126633336671.jpg

而且我可以在我的ios设备库中找到图片。

[当我尝试通过react-native-fs删除图片时

这里是代码:

if (this.state.path !== '') {    
  RNFS.unlink(this.state.path).then(() => {
    console.log('DELETED PHOTO');
  })
  // `unlink` will throw an error, if the item to unlink does not exist
  .catch((err) => {
    console.log(err.message);
  });
}

我可以在调试模式下看到DELETED PHOTO。但是图片仍然在我设备的图库中。

任何人都知道如何解决它?

更新:我尝试通过

更改文件路径
const filePath = this.state.path.split('///').pop()  // removes leading file:///

仍然无法使用。

react-native react-native-camera react-native-fs
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.