I am trying to use the new @angular/fire 5.1.0
to view an image uploaded to firebase using AngularFireStorage.
I used to be able to make use of task.downloadURL()
in angularfire2
"correct me if I'm wrong but now I have to use afStorage.getDownloadURL()
Please can you kindly assist me with setting imageUrl correctly.
import { AngularFireStorage, AngularFireStorageReference, AngularFireUploadTask } from '@angular/fire/storage'
....
downloadURL: Observable<string>;
imageUrl: string;
....
async onGetFromGallery(){
try{ ....
const imageData = await this.camera.getPicture(options);
const image = 'data:image/jpeg;base64,' + imageData;
const id = Math.random().toString(36).substring(2);
const user = this.authenticatorService.getUser();
this.ref = this.afStorage.ref(user.uid + '/images/categories/'+id);
this.task = this.ref.putString(image, 'data_url');
//--- Previously:angularfire2:
// this.downloadURL = this.ref.getDownloadURL();
// this.downloadURL.subscribe(url=> this.imageUrl=url);
//--- now replaced by this.ref.getDownloadURL()...
//My Attempt - unable to getDownloadUrl?
this.task
.snapshotChanges().toPromise().then(_ =>
{
this.ref.getDownloadURL().toPromise().then(res => {
console.log('URL: ', res);
this.imageUrl = res;
});
})
} catch(e) {
console.error(e);
this.errorMessage = JSON.stringify(e);
}
}
view excerpt:
<img [src]="imageUrl" style="width:100%;">
package.json excerpt:
"@angular/compiler-cli": "5.2.11",
"@angular/fire": "^5.1.0",
"firebase": "^5.5.9",
"cordova-android": "~7.0.0",
Thank you.