我从同事那里获得了存储桶名称,访问密钥和区域。
我想将图像上传到s3存储桶。
我该怎么做?
谢谢!
答案 0 :(得分:0)
嘿,广汇金
您可以使用react-native-s3-upload
包将图像上传到s3存储桶。
import { RNS3 } from 'react-native-s3-upload';
constructor(props) {
super(props)
this.state = {
amazonData: [],
pictures:''
}
}
takePics = () => {
ImagePicker.openPicker({
multiple: true,
maxFiles: 3
}).then(response => {
store.amazonData = [];
let tempArray = []
response.forEach((item) => {
let image = {
uri: item.path,
width: item.width,
height: item.height,
name: item.filename,
type: 'image/png'
}
const config = {
bucket: 'goodvet',
region: 'ap-northeast-2',
accessKey: 'AKIAIJ4ZNXCKL6CIYIXQ',
secretKey: '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',
successActionStatus: 201
}
tempArray.push(image)
RNS3.put(image, config)
.then(responseFromS3 => {
this.setState({ amazonData: [...this.state.amazonData, responseFromS3.body.postResponse.location] })
})
})
this.setState({ pictures: tempArray })
{ this.hideIcons() }
})
}
takePicHandler() {
return (
<View>
<SwiperFlatList
showPagination={this.state.showsPagination}
data={this.state.pictures}
renderItem={({ item }) =>
<View style={styles.uploadedImageView}>
<Image
style={{ width: "100%", height: "100%" }}
source={item} />
</View>
)
}
我希望这对您有用! :)
谢谢!
答案 1 :(得分:0)
您还应该检查来自AWS的Amplify框架(例如Storage.Put):