JavaScript attempting to get Firebase upload progress — uploadTask.on not a function

I'm trying to get the progress of a Firebase upload but the function I'm trying to watch the state with is apparently being called on the wrong object type:

Uncaught TypeError: uploadTask.on is not a function
    at VueComponent.submitUpload (eval at 100 (:8080/1.346d5d05d7c5f84c45e7.hot-update.js:7), <anonymous>:231:15)
    at boundFn (eval at <anonymous> (app.js:808), <anonymous>:125:14)
    at VueComponent.invoker (eval at <anonymous> (app.js:808), <anonymous>:1659:18)
    at VueComponent.Vue.$emit (eval at <anonymous> (app.js:808), <anonymous>:1930:16)
    at VueComponent.handleClick (eval at <anonymous> (app.js:1765), <anonymous>:6448:13)
    at boundFn (eval at <anonymous> (app.js:808), <anonymous>:125:14)
    at HTMLButtonElement.invoker (eval at <anonymous> (app.js:808), <anonymous>:1659:18)

Here's how I'm uploading the file:

 submitUpload: function(){
     var files = this.$refs.upload.uploadFiles;
     var storageRef = storage.ref();
     var pdfsRef = storageRef.child('files');
     var file = files[0]['raw'];
     var name = files[0]['name'];
     var fileref = storageRef.child(name);
     var self = this;
     var uploadTask = fileref.put(file).then(function(snapshot){
     console.log(name + ' is the filename');
     console.log('uploaded');
     var url = snapshot.downloadURL;
     self.gettext(url, name);
     });
     uploadTask.on('state_changed', function(snapshot){
     // Observe state change events such as progress, pause, and resume
     // 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 progress is: ' + progress);
     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) {
     // Handle unsuccessful uploads
     }, function() {
     // Handle successful uploads on complete
     // For instance, get the download URL: https://firebasestorage.googleapis.com/...
         var downloadURL = uploadTask.snapshot.downloadURL;
     });
 },

Can anyone tell me why the uploadTask variable doesn't have this function available, and how I can correct this? I suspect it's a problem with asynchronicity but I'm not sure how to wait until uploadTask is the right object type to watch its state.

Answer:1

The statement:

var uploadTask = fileref.put(file).then(...);

assigns to uploadTask the Promise returned by then(), instead of the UploadTask you want.

Change the statement to:

var uploadTask = fileref.put(file);
uploadTask.then(...);
Answer:2

I'm currently trying to receive the width and height of a canvas. The canvas is using a style parameter as you can see in the following code: <canvas id="ctx" style="height: calc(100vh - 142px); ...

I'm currently trying to receive the width and height of a canvas. The canvas is using a style parameter as you can see in the following code: <canvas id="ctx" style="height: calc(100vh - 142px); ...

  1. canvas width height css
  2. canvas width height 100
  3. canvas width height javascript
  4. canvas width height responsive
  5. canvas width height tkinter
  6. canvas width height
  7. canvas width height auto
  8. canvas width height percent
  9. canvas width height style
  10. canvas width height html
  11. canvas width height dynamic
  12. canvas width height percentage
  13. canvas width height parent
  14. canvas width height 0
  15. canvas width height scale
  16. canvas width height change
  17. canvas width height jquery
  18. canvas width height set
  19. canvas width height get
  20. createelement canvas width height

What is the difference between the two? // Chrome console Array(2); // [undefined × 2] Array(2).map(() => 1); // [undefined × 2] [...Array(2)]; // [undefined, ...

What is the difference between the two? // Chrome console Array(2); // [undefined × 2] Array(2).map(() => 1); // [undefined × 2] [...Array(2)]; // [undefined, ...

  1. what difference between bourbon and whiskey
  2. what difference between vegan and vegetarian
  3. what difference between psoriasis and eczema
  4. what difference between flu a and b
  5. what difference between ipad and ipad air
  6. what difference between republic and democracy
  7. what difference between inc and llc
  8. what difference between chromebook and laptop
  9. what difference between md and do
  10. what difference between virus and bacteria
  11. what difference between w2 and w4
  12. what difference between perfume and eau de toilette
  13. what difference between cold and flu
  14. what difference between catholic and christian
  15. what difference between diabetes 1 and 2
  16. what difference between california king and king
  17. what difference between macbook air and pro
  18. what difference between airpod 1 and 2
  19. what difference between medicare and medicaid
  20. what difference between bipolar 1 and 2

I need to build two force graphs using d3 and make them both zoom/pan at the same time. I'm acheving this by forcing the d3.event.scale() and d3.event.translate() properties from within the zoom event ...

I need to build two force graphs using d3 and make them both zoom/pan at the same time. I'm acheving this by forcing the d3.event.scale() and d3.event.translate() properties from within the zoom event ...

I have component that looks something like this: <text-field name=myusername>Username</text-field> I'd like to place "Username" in the placeholder attribute of an input, kind of like ...

I have component that looks something like this: <text-field name=myusername>Username</text-field> I'd like to place "Username" in the placeholder attribute of an input, kind of like ...

  1. angular ng-content attribute
  2. angular ng-content select attribute
  3. angular 2 ng-content attribute