Cannot call .then on UploadTask
See original GitHub issueVersion 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:
- Created 6 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@davideast Sorry I’m very busy lately. If no one will do the PR I will try to do it next week.
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!