【发布时间】:2020-03-21 07:47:33
【问题描述】:
我正在开发一项功能来删除上传的文件。我目前可以删除 Cloud Firestore 中的引用,但无法从存储中删除它。下面的代码应该从存储中删除,但它不起作用
private void deleteImage(String id, final int position, String fileUrl) {
StorageReference storageRef = FirebaseStorage.getInstance().getReference("uploads");
// Create a reference to the file to delete
StorageReference fileRef = storageRef.child(fileUrl);
// Delete the file
fileRef.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!
}
});
}
错误消息是“没有请求的身份验证令牌。发生了 StorageException。对象在该位置不存在。HttpResult:404”。我认为问题与我的 fileUrl 字段有关,但我不确定。 fileUrl 是下载图像的 url,例如,如果我将 url 复制并粘贴到网络浏览器上,我可以看到图像。为什么不工作?
【问题讨论】:
-
The fileUrl is the download image url,那是一个提供html页面的url。看起来不适合作为文件参考。
标签: android firebase firebase-storage