如何从/storage/emulated/0/Pictures中删除react原生图像裁剪选择器图像



捕获图像时,它会保存两个图像,一个是原始图像,另一个是压缩图像,并在image.path中给出压缩图像的路径。我如何才能禁用保存图库中的任何图像,我只需要使用base64?

ImagePicker.openCamera({
cropping: true,
width: 300*3,
height: 400*3,
includeBase64: true,
mediaType:'photo',
}).then(image => {
console.log('received image');
console.log(image)
})

输出如下:

cropRect: {height: 4128, width: 3096, y: 0, x: 0}
data: "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQ"
height: 900
mime: "image/jpeg"
modificationDate: "1581938243000"
path: "file:///storage/emulated/0/Pictures/398da0f6-73ee-47ce-bfdd-8b0fa68312a5.jpg"
size: 353210
width: 675

一个解决方法是删除保存的图像。你可以通过使用fs包

var RNFS = require('react-native-fs');
RNFS.exists(image.path)
.then(path => RNFS.unlink(path)) 

另外,它还保存在tmp目录中,所以也可以使用

ImagePicker.clean().then(..)

最新更新