【问题标题】:ionic 3 file uploading from filechooser to firebase storageionic 3 文件从文件选择器上传到 Firebase 存储
【发布时间】:2018-08-27 14:54:36
【问题描述】:

我正在尝试将 ionic 3 应用程序中的 pdf 上传到 firebase。 通过使用这种方法,我可以通过创建它们来上传文本文件。`

uploadToStorage(information):AngularFireUploadTask
  {
    let newName = `${new Date().getTime()}.txt`;
    return this.afST.ref(`files/${newName}`).putString(information);

  }`

这里是我调用函数的地方

uploadInfo(text)
  {
    let upload = this.dataProvider.uploadToStorage(text);

    upload.then(res=>{
      console.log('res',res);
      this.dataProvider.storeInfoOnDatabase(res.metadata,text).then(()=>{
        let toast = this.toastCtrl.create({
          message : 'New File Added',
          duration: 3000
        });
        toast.present();
      });
    });
  }

我需要做的是如何扩展uploadstorage() 函数以上传从离子文件选择器获取的文件

【问题讨论】:

    标签: firebase ionic-framework ionic3 firebase-storage


    【解决方案1】:

    在您的构造函数中包含 FirebaseApp

    然后使用以下代码(根据您的场景更改。以下是上传图片的代码)

    const pic = this.firebaseApp.storage().ref(path/filename.png);
    pic.putString(selectedPicture, 'base64', {contentType: 'image/png'})
        .then((savedImage) => {
            console.log(savedImage);
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-22
      • 2016-10-06
      • 2018-10-13
      • 1970-01-01
      • 2018-04-02
      • 2021-07-15
      • 2020-07-10
      • 2019-11-06
      相关资源
      最近更新 更多