Ionic 4-Firebase-存储未将数据发送到实时数据库 [英] Ionic 4 - Firebase - Storage not sending data to realtime Database

查看:89
本文介绍了Ionic 4-Firebase-存储未将数据发送到实时数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将图像上传到Firebase存储,然后我希望它们进入实时数据库,该代码在ionic v3中有效,但是现在看来有些错误,因为数据进入了存储,但不是数据库.

I'm uploading images to Firebase storage, and then i want them to go to the real time database, this code was working in ionic v3, but now it seems something is wrong since the data goes to the storage but not to the database.

    createPost(picture: string): Promise<any> {

        firebase.storage().ref('/home/')
            .child('picture.jpg')
            .putString(picture, 'base64', { contentType: 'image/jpg' })
            .then((savedPicture) => {
                firebase.database().ref('Home').push({
                    picture: savedPicture.downloadURL
                }).then(() => {
                    alert('Sucess');
                    this.navCtrl.navigateRoot('/home');
                })
            });
        return
}

推荐答案

新上载的下载URL不再作为savedPicture.downloadURL提供.上传完成后,您需要在存储参考上调用getDownloadURL():

The download URL of the new upload is no longer available as savedPicture.downloadURL. You will need call getDownloadURL() on the storage reference after the upload completes:

let ref = firebase.storage().ref('/home/').child('picture.jpg');
 ref.putString(picture, 'base64', { contentType: 'image/jpg' })
    .then((savedPicture) => {
        ref.getDownloadURL().then((url) => {
          firebase.database().ref('Home').push({
            picture: url
          }).then(() => {
            alert('Sucess');
            this.navCtrl.navigateRoot('/home');
          })
        })
    });

另请参阅:

  • The documentation on downloading a file via its URL
  • The documentation on monitoring upload progress

这篇关于Ionic 4-Firebase-存储未将数据发送到实时数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆