我创建了一个应用程序,该应用程序使用react-native-image-picker捕获照片并将其上传到Amazon s3。上传完成后,我想从图库中删除它们。当我搜索imagePicker API文档时,我了解了clean()方法。但是我没有在代码中使用它。
您能帮我解决这个问题吗?
我的代码是
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Alert,
Text,
TouchableOpacity,
View,
Picker,
Animated,
Easing,
Image
} from "react-native";
import ImagePicker from "react-native-image-picker";
import { RNS3 } from "react-native-aws3";
export default class SecondScreen extends Component<Props> {
constructor(props) {
super(props);
this.state = {
file: "",
saveImages: []
};
}
takePic() {
const options = {
quality: 1.0,
maxWidth: 50,
maxHeight: 50,
}
ImagePicker.launchCamera(options,(responce)=>{
const file = {
uri: responce.uri,
name: responce.fileName,
method: "POST",
path: responce.path,
type: responce.type,
notification: {
enabled: true
}
};
this.state.saveImages.push(file);
});
}
_upload = saveImages => {
const config = {
keyPrefix: "uploads/",
bucket: "s3merahkee",
region: "us-east-2",
accessKey: "***",
secretKey: "***",
successActionStatus: 201
};
this.state.saveImages.map(image => {
RNS3.put(image, config).then(responce => {
console.log(saveImages);
});
});
//once after upload is done delete from the gallary
};
render() {
return (
<View style={styles.container}>
<View style={styles.Camera}>
<TouchableOpacity onPress={this.takePic.bind(this)}>
<Text>Take Picture</Text>
</TouchableOpacity>
</View>
<View style={styles.Send}>
<TouchableOpacity onPress={() => this._upload()}>
<Text>Send</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
答案 0 :(得分:0)
安装react native react-native-fs这个帮助可以删除您的映像。
import { RNCamera } from 'react-native-camera';
import RNFS from 'react-native-fs';
takePhoto = async () => {
const data = await this.camera.takePictureAsync();
// Do what you need with the image and then…
RNFS.unlink(data.uri); // Remove image from cache
}