question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot call .then on UploadTask

See original GitHub issue

Version info

Angular: 1.4.3

Firebase: 3.7.5

AngularFire: 2.3.0

Browser: Chrome 56.0.2924.87

Steps to reproduce

const imageStorageRef = firebase.storage().ref('images')
const imageStorage = $firebaseStorage(imageStorageRef)
const uploadTask = imageStorage.$putString(image, 'base64')

uploadTask.then((snap) => {
  console.log('downloadURL:', snap.downloadURL)
})

Expected behavior

Log the download URL successfully.

Actual behavior

An error occurred on Firebase SDK (not on the AngularFire): TypeError: Cannot read property 'then' of undefined.


Hi, I have an unexpected behavior as specified above. But if I use imageStorage.putString(...) that is the method not wrapped by AngularFire, the error disappear. I also tried changing the following lines on AngularFire (https://github.com/firebase/angularfire/blob/master/src/storage/FirebaseStorage.js#L40):

From

      $cancel: task.cancel,
      $resume: task.resume,
      $pause: task.pause,
      then: task.then,
      catch: task.catch,
      $snapshot: task.snapshot
};

to

      $cancel: task.cancel,
      $resume: task.resume,
      $pause: task.pause,
      then: task.then.bind(task),
      catch: task.catch.bind(task),
      $snapshot: task.snapshot
};

Which add .bind(task) to the then and catch methods and now it works as expected. Not sure if this is a correct solution.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
deoxen0n2commented, Apr 25, 2017

@davideast Sorry I’m very busy lately. If no one will do the PR I will try to do it next week.

1reaction
jwngrcommented, Apr 6, 2017

Seems like we might need to bind task to all of those methods actually so they have the proper scope. I’m surprised the tests pass as is though… I don’t have time to look into this, but maybe David (who wrote the initial code) does. Otherwise, if you can find a failing test and put together a PR which fixes it, that would be awesome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase Storage Web: uploadTask.cancel() is not working ...
When cancelling, call the below cancel function instead of using a cancel state. const onCancel = () => { //with the ref, we...
Read more >
UploadTask | Firebase JavaScript API reference
Reference for UploadTask. ... If more than just the event argument is passed, returns a function you can call to unregister the callbacks....
Read more >
uploadTaskWithRequest:fromFile: fa… - Apple Developer
I have added a check if file exists and then launch upload task but the app randomly crashes with. NSInvalidArgumentException Reason:Cannot read file...
Read more >
uploadtask.on is not a function - You.com | The AI Search ...
var uploadTask = fileref.put(file); uploadTask.then(...); Open side panel. Is it possible to turn firebase's image upload "uploadTask.on" listener into a ...
Read more >
Firebase v9 Storage in React | Upload Files to Cloud - YouTube
Copy link. Info. Shopping. Tap to unmute. If playback doesn't begin shortly, try restarting your device. Your browser can't play this video.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found