从存储方法中删除Firebase会引发找不到对象的错误

时间:2017-09-20 20:46:20

标签: angular firebase firebase-storage

我正在尝试从我的firebase存储中删除文件,但我一直收到此错误

  

FirebaseStorageError {code_:“storage / object-not-found”,message_:“Firebase存储:对象'products_img / test_8xtx7e9wkf_FOODBANK_(1).png'不存在。”,serverResponse_:“{↵”错误“:{ ↵“代码”:404,↵“消息”:“未找到。无法删除对象“↵}↵}”,name_:“FirebaseError”}

关于此代码

  public delete() {
      if (!confirm('Are you sure you want to delete this product')) return;
      this._productService.delete(this.id);
      this.product.images.forEach(d => {
          this.uploadform.deleteFileStorage(d.name);
      });
      this._router.navigate(['/admin/products']);
  }

但如果我这样做,它会删除而不会出错

  public delete() {
      if (!confirm('Are you sure you want to delete this product')) return;
      this._productService.delete(this.id);
      this.uploadform.deleteFileStorage(this.product.images[0].name);
      this._router.navigate(['/admin/products']);
  }

这是文件删除服务中的方法

  public deleteFileStorage(file) {
    const storageRef = firebase.storage().ref();
    storageRef.child(`${this.basePath}/${file.name}`).delete();
  }

如果您想提供帮助但需要查看整个源代码,请发表评论,我会与您分享。

0 个答案:

没有答案