【问题标题】:url not defined. Refactor to new versions of angularfire, angular网址未定义。重构为新版本的 angularfire, angular
【发布时间】:2019-01-21 09:23:57
【问题描述】:

我有重构问题,因为我的代码不适用于新版本的 angular 和 angularfire。

错误

行:upload.url = uploadTask.snapshot.downloadURL;未定义。

代码

uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
  // three observers
  // 1.) state_changed observer
  (snapshot) => {
    // upload in progress
    upload.progress = (uploadTask.snapshot.bytesTransferred / uploadTask.snapshot.totalBytes) * 100;
    console.log(upload.progress);
  },
  // 2.) error observer
  (error) => {
    // upload failed
    console.log(error);
  },
  // 3.) success observer
  (): any => {

    upload.url = uploadTask.snapshot.downloadURL; //?!?!UNDEFINED
    upload.name = upload.file.name;
    this.saveFileData(upload);
  }
);

问题

我曾尝试过来自 stackoverflow 的不同解决方案,但它并没有真正奏效。大多数示例也更多地是关于如何检索图像,但我想将变量 upload.url 设置为一个值。

另一个问题: 我是角度和网络的新手。将其更改为firestore需要很长时间吗?该代码基于实时firebase。

【问题讨论】:

标签: firebase undefined firebase-storage angularfire2 angular6


【解决方案1】:

要获取downloadURL,必须调用Storage Reference ObjectgetDownloadURL()方法。

试试这个:

uploadTask.snapshot.ref.getDownloadURL()
    .subscribe(url => console.log(url))

【讨论】:

    猜你喜欢
    • 2019-12-20
    • 1970-01-01
    • 2015-09-30
    • 2017-12-12
    • 2015-05-07
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 2018-04-21
    相关资源
    最近更新 更多