简体   繁体   English

Ionic 4-Firebase-存储未将数据发送到实时数据库

[英]Ionic 4 - Firebase - Storage not sending data to realtime Database

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. 我正在将图像上传到Firebase存储,然后希望它们进入实时数据库,该代码在ionic v3中有效,但是现在看来有些问题了,因为数据进入了存储而不是数据库。

    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
}

The download URL of the new upload is no longer available as savedPicture.downloadURL . 新上载的下载URL不再作为savedPicture.downloadURL You will need call getDownloadURL() on the storage reference after the upload completes: 上传完成后,您需要在存储参考上调用getDownloadURL()

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');
          })
        })
    });

Also see: 另请参阅:

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

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