Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular FireBase Storage downloadURL在Ionic 3中未设置正确的值_Angular_Firebase_Ionic3_Firebase Storage - Fatal编程技术网

Angular FireBase Storage downloadURL在Ionic 3中未设置正确的值

Angular FireBase Storage downloadURL在Ionic 3中未设置正确的值,angular,firebase,ionic3,firebase-storage,Angular,Firebase,Ionic3,Firebase Storage,我使用下面的代码块将音频文件发送到FireBase存储,然后将这些记录添加到表中,以保留每个post记录的下载链接 private doPost() { const fileName = this.navParams.get('name').replace(/^.*[\\\/]/, ''); const filePath = 'file://' + this.navParams.get('path'); const fullPath = this.navParams.ge

我使用下面的代码块将音频文件发送到FireBase存储,然后将这些记录添加到表中,以保留每个post记录的下载链接

private doPost() {
    const fileName = this.navParams.get('name').replace(/^.*[\\\/]/, '');
    const filePath = 'file://' + this.navParams.get('path');
    const fullPath = this.navParams.get('name');

    this.file.resolveDirectoryUrl(filePath).then((rootDir) => {
      this.file.getFile(rootDir, fileName, { create: false }).then((fileEntry) => {
        fileEntry.file((file) => {
          const reader = new FileReader();
          reader.onloadend = (res: any) => {
            let result = res.target.result
            let blob = new Blob([new Uint8Array(result)], { type: 'audio/mp3' })
            const upload = this.storage.ref('files/' + fileName).put(blob);
            console.log("download url " + upload.downloadURL);
            const postModel = {
              uID: this.uID,
              text: this.postText,
              time: new Date().getTime().toString(),
              downloadURL: upload.downloadURL.toString()
            }
            this.dataProvider.add(postModel, '/Post/');
            // this.dataProvider.addPost(postModel);
          }
          reader.readAsArrayBuffer(file);
        })
      })
      .catch((err) => {
        console.log("Get File'da hata: " + err)
      })
    })
    .catch((err) => {
      console.log("Directory Hatalı!");
    })
  }
但是downloadURL值没有设置正确的值,下面是这个代码块设置的记录

downloadURL: "function () { return Object(__WEBPACK_IMPORTED_MODULE_2_rxjs_observable_from__[\"from\"])(task.then(function (s) { return s.downloadURL; })); }"

upload.downloadURL
在成功上传后发出可观察的字符串类型。首先订阅以获取url,然后执行添加操作

试一试


谢谢您。如果我再次在设备上成功运行我的应用程序,我将尝试:)
upload.downloadURL().subscribe(url=>{
    if(url){
        const postModel = {
          uID: this.uID,
          text: this.postText,
          time: new Date().getTime().toString(),
          downloadURL: url
        }
        this.dataProvider.add(postModel, '/Post/');
        // this.dataProvider.addPost(postModel);
    }
}