代码之家  ›  专栏  ›  技术社区  ›  Aizen

AngularFire FirebaseStorage回调无法从快照方法工作

  •  0
  • Aizen  · 技术社区  · 6 年前

    这是为了angularforestorage,我上传了一个图片后,我计划得到下载的url,但问题是,用于observate的管道不工作,我还试图使用{tap}但没有成功。

    这是密码

        const path = `hospital/${new Date().getTime()}_${file.name}`;
    
    const customMetadata = { app : 'PROV-H meta'};
    
    const ref = this.storage.ref(path);
    
    this.task = ref.put(file,{customMetadata});
    
    
    this.percentage = this.task.percentageChanges();
    
    this.snapshot = this.task.snapshotChanges().pipe(
      finalize(()=>{
        console.log("percent finalize");
      })
    );
    

    这是控制台的日志。

    XHR finished loading: GET "http://localhost:4200/sockjs-node/info?t=1540028075438".
    

    https://firebasestorage.googleapis.com/v0/b/prov-h-fae96.appspot.com/o?name=hospital%2F1540028079723_caps.png ".

    仅供参考,如果无法使回调工作,则无法订阅下载URL。

     this.snapshot = this.task.snapshotChanges().pipe(
      finalize(()=>{
        console.log("percent finalize"); //THIS IS NOT GETTING CALLED;
      })
    );
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   Oscar    5 年前

    就这样做:

    this.snapshot = this.task.snapshotChanges().pipe(
     finalize(()=>{
       console.log("percent finalize");
       })
     );
     this.snapshot.subscribe(
      res => {
        console.log(res);
      }, err => {
        console.log(err);
      }
    );