如何从 firebase 存储中删除图像本机反应

How to delete image from firebase storage react native

我想在用户删除帐户时删除上传到 firebase 存储的图像。我阅读了文档并尝试了他们指定的内容,但它不起作用。我回来了 error error Error: No object exists at the desired reference.

console.log 显示

{path: "/users/w3jvGrcMJ7TSUguQRRvRa8eHEIF3/undefined", _storage: Storage}path: "/users/w3jvGrcMJ7TSUguQRRvRa8eHEIF3/undefined"_storage: Storage {_app: App, _customUrlOrRegion: undefined, namespace: "storage"}fullPath: (...)key: (...)put: (...)__proto__: ReferenceBase "ref"

deleteaccount.js

try{
const user = firebase.auth().currentUser;
    let uid = user.uid;
let ref = firebase.storage().ref(`/users/${uid}/`).child()
    console.log(ref,'ref')  
await ref.delete()

} catch(e){

console.log(e)

}

好像是对的,你能试试这样吗?

// Create a reference to the file to delete
var desertRef = firebase.storage().child('images/example.jpg');

// Delete the file
desertRef.delete().then(function() {
  // File deleted successfully
}).catch(function(error) {
  // Uh-oh, an error occurred!
});
let imageRef = storage.refFromURL(URL);
imageRef.delete()