如何从Firebase存储中删除图像React Native

时间:2019-06-11 18:22:48

标签: reactjs react-native react-native-firebase

我要在用户删除帐户时删除上传到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)

}

2 个答案:

答案 0 :(得分:0)

这似乎是正确的,您可以尝试这样的事情吗?

// 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!
});

答案 1 :(得分:0)

let imageRef = storage.refFromURL(URL);
imageRef.delete()