如何使用Kotlin删除这张照片? 您能帮我解决这个问题吗?
科特琳
private fun uploadPhoto() {
if (selectedPhotoUri == null) return
val filename = UUID.randomUUID().toString()
val ref = FirebaseStorage.getInstance().getReference("/Users/$filename")
ref.putFile(selectedPhotoUri!!)
.addOnSuccessListener {
ref.downloadUrl.addOnSuccessListener {
url = it.toString()
store(url!!)
}
}
.addOnFailureListener {
Toast.makeText(this, "", Toast.LENGTH_LONG).show()
}
}
答案 0 :(得分:0)
首先,您需要获取要删除的照片的参考。您可以使用图像的url或其他方法来访问图像的引用。以下代码直接来自Firebase文档。
StorageReference desertRef = mFirebaseStorage.getReferenceFromUrl(mImageUrl);
// Delete the file
desertRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// File deleted successfully
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Uh-oh, an error occurred!
}
});