Firebase Web / Uploading file to Firebase Storage Not Working
Firebase Web / Uploading file to Firebase Storage Not Working
I've watched 'Getting Started with Firebase Storage on the Web' on YouTube. I applied it to my code, and it worked perfectly. But I wanted uploading step separately from selecting file step. So I created upload button and added event listener to the button. (Thus, I basecally separated the code from the video into two event listener functions because, again, I wanted selecting a file and uploading the file two separate actions).
I really don't understand why it's not working. It doesn't give me any error on my log console. Could anybody please tell me WHY this is not working and HOW I can fix this? Thank you.
var uploader = document.getElementById('uploader');
var fileButton = document.getElementById('fileButton');
var uploadButton = document.getElementById('uploadButton');
var file;
fileButton.addEventListener('change', function(e)
file = e.target.files[0];
);
uploadButton.addEventListener('click', function(e)
var fileName = file.name;
var storageRef = firebase.storage().ref('images/' + fileName);
var task = storageRef.put(file);
task.on('state_changed',
function progress(snapshot)
var percentage = (snapshot.bytesTransferred/snapshot.totalBytes) * 100;
uploader.value = percentage;
,
function error(err)
,
function complete()
);
window.alert('Upload Done');
);
1 Answer
1
As you can see, the docs do not use named functions inside the callbacks, how about converting them into anonymous functions?
And also, how can you be sure that there isn't an error if you are not using console.log() on the error callback...
console.log()
Remember that the console will not be displaying any error if it's not handle by the console methods
Firebase Upload Files - Monitor Upload Progress
Yep, I'm not hoping that works 100%, but is worth to try, the other thing is to add the
console.error() to the error function– Benjamín Vázquez
Aug 21 at 14:24
console.error()
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Inside callbacks, so you mean changing function progress(snapshot) into function(snapshot), for example?
– FiveChickens
Aug 20 at 21:31