Skip to content

Commit 5d1f82b

Browse files
authored
add firebase url save
Added code that made sure that the uploaded image's url is saved in database //
1 parent b1700ba commit 5d1f82b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

upload.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
150150
// Upload completed successfully, now we can get the download URL
151151
var downloadURL = uploadTask.snapshot.downloadURL;
152152
console.log("The download URL: "+downloadURL);
153+
154+
//this is where you have to enter the code to update any desired firebase table with the image url
155+
//eg this below code will add a 'profilePhoto' field and record to 'users' table for the user with the id of userId
156+
//read more about saving data in firebase here: https://firebase.google.com/docs/database/web/save-data
157+
158+
firebase.database().ref('users/' + userId).update({
159+
profilePhoto: downloadURL
160+
});
161+
153162
});
154163

155164

@@ -159,7 +168,7 @@ uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
159168
function onFail(message) {
160169
//alert('Failed because: ' + message);
161170
setTimeout(function(){
162-
navigator.notification.alert(message);
171+
navigator.notification.alert(message); //show a pop up message if something failed in the process eg.image upload canceled
163172
}, 0);
164173
}
165174

0 commit comments

Comments
 (0)