0

我正在尝试遵循 firebase 文档并使用聚合物将图像上传到 firebase。

这就是我所拥有的

  _pushToFirebase: function() {

       // SLUGGING THE NAME B4 WE EVEN SAVE IT!!
      var sluggedname = this._slugify(this.$.crewName.value);
      //FOR THE IMAGE
      var file = this.$.crewProfilePic.value;

      // Upload file
      var uploadTask = this.$.query.storageRef.child('/crewprofileimages/' + file.name).put(file);
      // Listen for state changes, errors, and completion of the upload.
      uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
        function(snapshot) {
          // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
          var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
          console.log('Upload is ' + progress + '% done');
          switch (snapshot.state) {
            case firebase.storage.TaskState.PAUSED: // or 'paused'
              console.log('Upload is paused');
              break;
            case firebase.storage.TaskState.RUNNING: // or 'running'
              console.log('Upload is running');
              break;
          }
        }, function(error) {
        switch (error.code) {
          case 'storage/unauthorized':
            // User doesn't have permission to access the object
            console.log('You dont have permission to access object');
            break;

          case 'storage/canceled':
            // User canceled the upload
            console.log('User cancelled upload');
            break;

          case 'storage/unknown':
            // Unknown error occurred, inspect error.serverResponse
            console.log(error.code);
            break;
        }
      }, function() {
        // Upload completed successfully, now we can get the download URL
        var downloadURL = uploadTask.snapshot.downloadURL;
      });




      // PUSHING TO FIREBASE
      this.$.query.ref.push({
        name: this.$.crewName.value,
        description: this.$.crewDescription.value,
        createddate: new Date().toString(),
        creator: this.$.createcrewlogin.user.uid,
        slug: sluggedname,
        profileimage: downloadURL,
        members: {
          memberuserid: this.$.createcrewlogin.user.uid,
        }
      });
  },

firebase 查询看起来像这样

    <!--STORE THE DATA IN CREWS DEFAULT SECTION-->
    <firebase-query
      id="query"
      data="{{mycrews}}"
      path="/crews">
    </firebase-query>

每当我点击提交。我在控制台中收到此错误

cannot read property of 'child' of undefined 我该如何解决这个问题?

4

1 回答 1

0

可能迟到了,但从简短的错误来看,您尝试访问的元素似乎未定义,即,您需要在请求属性之前访问它(此处为子元素)

Firebase-query 有一个 path 属性,它是您可以保存数据的位置。如果您使用polymerfire 元素作为firebase-query,那么您需要访问路径并更改它,然后push()。

所以而不是

this.$.query.storageRef.child('/crewprofileimages/' + file.name).put(file);

你应该有类似的东西:

this.$.query.path = yourPath ; 
this.$.query.put(file) ... etc 

您提出的错误来自于此,但为了获得更好的解决方案,需要提供更好的错误。干杯

于 2017-04-09T10:23:03.747 回答