I\'m trying to get downloadUrl for an image from firebase, All properties like \'timeCreated\', \'fullPath\', \'contentType\' are working well & pushed correctly! but I don\
THX Doug, you're right.
The correct code is like this:
captureAndUpload() {
this.data.captureImage().then(data => {
let upload = this.data.uploadImage(data);
upload.then().then(res => {
this.data.storeImageInformation(res);
});
}
Data Provider:
uploadImage(image) {
let storageRef: AngularFireStorageReference;
let newName = `${new Date().getTime()}-${this.afAuth.auth.currentUser.uid}.png`;
storageRef = this.afStorage.ref(`/images/${this.afAuth.auth.currentUser.uid}/${newName}`);
return storageRef.putString(image, 'base64', { contentType: 'image/png'})
.snapshotChanges().toPromise().then(_ =>
{
return storageRef.getDownloadURL().toPromise().then(res => {
console.log('URL: ', res);
return res;
});
}
)
}
storeImageInformation(downloadURL) {
return this.db.object(`/images/${this.afAuth.auth.currentUser.uid}`).update({img: downloadURL}); }
The download URL is now no longer accessible in the immediate results of the upload. This change was made a few months ago to the Firebase client SDKs.
Instead, you will have to call getDownloadURL (or whatever the Angular binding is for that JavaScript function) to get the URL as a second request after the upload is complete.