首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用getDownloadURL() (带令牌)获取完整的url?

如何使用getDownloadURL() (带令牌)获取完整的url?
EN

Stack Overflow用户
提问于 2019-06-20 00:36:31
回答 1查看 334关注 0票数 -1

未处理的承诺拒绝:FirebaseStorageError{code_:“存储/找不到对象”,message_:"Firebase存储:对象'k91a73uzb99‘不存在。“,serverResponse_:"{↵”错误“:{↵”代码“:404,↵”消息“:"No…not get object",状态“:”GET_OBJECT“↵}↵}”,name_:"FirebaseError"}

代码语言:javascript
复制
export class ReportComponent implements OnInit {

  ref: AngularFireStorageReference;
  task: AngularFireUploadTask;
  newUrl: Observable<string>;

  constructor(private firesStore: AngularFireStorage,
              ) { }

  ngOnInit() { }

  async onSelectFile(event) {
    const id = Math.random().toString(36).substring(2);

    this.ref = this.fireStore.ref(id);
this.task = this.ref.put(event.target.files[0]); /*
        .snapshotChanges()
            .subscribe( (value) => {
            }); */

this.uploadPercent = this.task.percentageChanges();
// get notified when the download URL is available
this.task.snapshotChanges().pipe(
      finalize(() => {
        this.newUrl = this.ref.getDownloadURL();
        console.log(this.newUrl);
      })
).subscribe();

}

预期:https://firebasestorage.googleapis.com/v0/b/< storageBucket >/o/< ref(id) >?alt=media&token=<........>

实际:https://firebasestorage.googleapis.com/v0/b/< storageBucket >/o/< ref(id) >

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-20 00:44:08

错误消息显示“存储/未找到对象”和“对象'k91a73uzb99‘不存在”。这意味着您正在上传的文件包含以下代码行:

代码语言:javascript
复制
this.ref = this.firesStore.ref(id);
this.task = this.ref.put(event.target.files[0]);

尚未完成上传。您正在尝试在上载完成之前获取其下载URL:

代码语言:javascript
复制
this.newUrl = await this.firesStore.ref(id).getDownloadURL();

您需要遵循使用返回的AngularFireUploadTask的example code from the documentation,在访问其下载URL之前等待上传完成。所以,它会是这样的:

代码语言:javascript
复制
this.uploadPercent = task.percentageChanges();
// get notified when the download URL is available
task.snapshotChanges().pipe(
    finalize(() => this.newUrl = this.ref.getDownloadURL() )
 )
.subscribe()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56672315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档