小编Ama*_*wal的帖子

React Native文件处理 - 删除图像

我正在使用react-native-camera点击图片.我得到了一个文件路径,如:"file:///storage/emulated/0/Pictures/IMG_20161228_021132.jpg",来自我在相机中存储的相机数据.我能够使用它作为使用Image组件"Image source = {{uri:this.props.note.imagePath.path}}"显示Image的源,并且它正在显示.

现在我想添加删除图像功能.有人可以建议如何使用上述路径在手机中访问此图像并将其从手机中删除.

我检查了react-native-filesystem但是当我使用checkIfFileExists函数传递这个路径时,我得知该文件不存在.不确定出了什么问题.

async checkIfFileExists(path) {

const fileExists = await FileSystem.fileExists(path);
//const directoryExists = await FileSystem.directoryExists('my-directory/my-file.txt');
console.log(`file exists: ${fileExists}`);
//console.log(`directory exists: ${directoryExists}`);
}


deleteNoteImage (note) {

console.log(note.imagePath.path);

//check if file exists
this.checkIfFileExists(note.imagePath.path);
//console.log();

note.imagePath = null;
this.updateNote(note);
}
Run Code Online (Sandbox Code Playgroud)

远程调试快照

delete-file react-native

7
推荐指数
2
解决办法
8591
查看次数

标签 统计

delete-file ×1

react-native ×1