Ionic 3 + Firebase Storage Получить изображение профиля

1

У меня есть этот код:

/////////////////////////////////////////////CROP + UPLOAD FOR FIREBASE STORAGE//////////////////////////

  // Return a promise to catch errors while loading image
  getMedia(): Promise<any> {
    // Get Image from ionic-native built in camera plugin
    return Camera.getPicture(this.options)
      .then((fileUri) => {
        // Crop Image, on android this returns something like, '/storage/emulated/0/Android/...'
        // Only giving an android example as ionic-native camera has built in cropping ability
        if (this.platform.is('ios')) {
          return fileUri
        } else if (this.platform.is('android')) {
          // Modify fileUri format, may not always be necessary
          fileUri = 'file://' + fileUri;
          /* Using cordova-plugin-crop starts here */
        return Crop.crop(fileUri, { quality: 100 });
      }
      }).then((path) => {
         // path looks like 'file:///storage/emulated/0/Android/data/com.foo.bar/cache/1477008080626-cropped.jpg?1477008106566'
        //  console.log('Cropped Image Path!: ' + path);
        path; // return the path of file
        window.resolveLocalFileSystemURL(path, FE=>{
          FE.file(file=>{
             const FR=new FileReader()
             FR.onloadend = ((res: any)=>{
               let AF=res.target.result
               let blob=new Blob([new Uint8Array(AF)], {type: 'image/jpg'});       
               this.upload(blob)
             });
             FR.readAsArrayBuffer(file);
             })
           })
         })
       }

       upload(blob:Blob){
         const currentUserId = this.fire.auth.currentUser.uid; // get user UID in firebase
         this.Fbref.child('Profile/${currentUserId}/img').put(blob); //path in firebase storage


         ////GET Image URL 
         this.Fbref.child('Profile/${currentUserId}/img' ).getDownloadURL().then(function(url){
         console.log("the URL Image is: " + url);
         url;
         let photoURL = this.url

});}

Он отлично работает, снижается ли изображение, а затем загружается.... но я не могу сохранить URL-адрес изображения внутри профиля пользователя DOC в базе данных Firestore.

Необходимо поместить в качестве photoURL: (URL-изображение)

кто нибудь знает как это сделать?

Теги:
google-cloud-firestore
ionic3
firebase-storage

1 ответ

1
Лучший ответ

[SOLVED] Добавление кода ниже отлично работает

savephotoURL(){
  const currentUserId = this.fire.auth.currentUser.uid;
  this.Fbref.child('Profile/${currentUserId}/img' ).getDownloadURL().then(function(url){
  console.log("the URL Image is: " + url);
  let imageURL = url
  return imageURL
}).then((imageURL) => {
  this.database.doc('ProfileUser/${currentUserId}/').update({photoURL:imageURL})  })// save url in Firestore database realtime
}
  • 0
    Привет @Juliano JC у вас есть репо на этом? Загрузка и отображение изображения ionic 3 с помощью firebase испытывают некоторые проблемы. Буду признателен за ваш отзыв. Благодарю.
  • 0
    Здравствуйте! ... Я создал хранилище сейчас, оно находится по ссылке ниже, я надеюсь, что это может помочь вам ... Я также нашел время, чтобы заставить код работать ... если есть какие-либо сомнения, отправьте его в github [ github.com / Julianojc / Firebase-Storage-Upload]
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню