如何使用react native中的图像的URL删除Firebase存储中的图像?
这是数据的结构
list {
["https://firebasestorage.googleapis.com/v0/b/testes-109.appspot.com/o/photos%2FmdWs20BYhSdR4XIePdpBL9szC7i2%2F79337645-7aa6-4fa3-ab29-9dae6f41bc6?alt=media&token=a9cc2795-f118-485c-94b9-cdf0c083eb2a", "https://firebasestorage.googleapis.com/v0/b/testes-109.appspot.com/o/photos%2FmdWs20BYhSdR4XIePdpBL9szC7i2%2F79337645-7aa6-4fa3-ab29-9dabe6f41bc6?alt=media&token=a9cc2795-f118-48c-94b9-cdf0c83eb2a", ],
}
我尝试过这个
<FlatList
data={list}
renderItem={({ item, index }) => {
return (
<View >
<TouchableOpacity onPress={() => this.deleteImage(item)} >
<Image source={{ uri: item }} style={{ width:100, height: 100 }} />
</TouchableOpacity >
</View>
)
}}
/>
deleteImage = (item) => {
alert(item)
var desertRef = item;
desertRef.delete()
.then(function() {
console.log('File deleted successfully')
}).catch(function(error) {
console.log('Uh-oh, an error occurred!')
});
}
但出现此错误
desertRef.delete不是功能。 (在'desertRef.delete()'中,'desertRef.delete'未定义]
您需要使用以下存储功能将其从存储中删除。
let imageRef =storage.refFromURL(-put URL of Image Here-);
imageRef.delete().then(() => {
console.log("Deleted")
}).catch(err => console.log))