最终目标是删除那些图像,如果这很重要的话,我在Firestore中的图像文件夹中有一个StorageReference
,位于同一范围内。
以下是代码片段:
private val images = ArrayList<MyImage>()
private val storageRef = Firebase.storage.reference
.child("images")
fun delete(position: Int): Boolean {
val toDelete = images[position].url
// And then what?
return true
}
MyImage
对象只包含图像的位图、用户生成的标题和下载url。
如何获取对该文件的引用并告诉Firestore将其删除?
您可以使用storage.refFromUrl((将下载URL转换为引用。
在任何情况下,只需将文件的路径与下载URL一起存储在存储器中就更容易了,这样更容易使用。