态
我创建了一个应用程序,该应用程序使用React-nimimage-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>
);
}
}
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
}
也请参考此https://github.com/itinance/reaect-native-fs/issues/34