Firebase Storage Put could not get object
Basically what Austin said, except we're smart (we are, trust me!) and we'll return the download URL in the promise after upload so you don't have to do the second fetch:
rainbowPhotoUploader.addEventListener('change', function(e){
//Get file
var file = e.target.files[0];
//Create a storage ref
var storageRef = firebase.storage().ref('rainbow_photos/' + file.name);
//Upload file
storageRef.put(file).then(function(snapshot){
$('#rainbowPhotoURL').val(snapshot.downloadURL);
});
});
You're getting the download link immediately after uploading, and it is not finished yet.
Do this to get the link after it's done uploading:
rainbowPhotoUploader.addEventListener('change', function(e){
//Get file
var file = e.target.files[0];
//Create a storage ref
var storageRef = firebase.storage().ref('rainbow_photos/' + file.name);
//Upload file
storageRef.put(file).then(function(result){
//Get URL and store to pass
storageRef.getDownloadURL().then(function(result){
$('#rainbowPhotoURL').val(result);
});
});
});