繁体   English   中英

将图像上传到 Firebase 存储后如何检索下载 Url,以便我可以将其保存到 Firebase 数据库?

[英]How to retrieve the download Url after uploading image to Firebase storage, so that I can save it to Firebase database?

下面的代码成功将图像上传到 Firebase 存储,但我想检索该确切图像的 downloadURL 并将其存储在“this.pichaMtumiaji”中,然后将其保存在 Firebase 数据库中。 我正在使用离子 3!

uploadPhoto(): void {
    this.myPhotosRef.child(this.generateUUID()).child('myPhoto.png')
      .putString(this.myPhoto, 'base64', { contentType: 'image/png' })
      .then((savedPicture) => {
        this.pichaMtumiaji = savedPicture.downloadURL().absoluteString;
      });
  }

generateUUID(): any {
  var d = new Date().getTime();
  var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx'.replace(/[xy]/g, function (c) {
    var r = (d + Math.random() * 16) % 16 | 0;
    d = Math.floor(d / 16);
    return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
  });
  return uuid;
}

基于Firebase 文档中关于上传文件的示例:

var ref = this.myPhotosRef.child(this.generateUUID()).child('myPhoto.png');
ref
  .putString(this.myPhoto, 'base64', { contentType: 'image/png' })
  .then((savedPicture) => {

    // Upload completed successfully, now we can get the download URL
    ref.getDownloadURL().then(function(downloadURL) {
      console.log('File available at', downloadURL);
      this.pichaMtumiaji = savedPicture.downloadURL().absoluteString;
    });

  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM