2017-09-01 106 views
0

我有上傳用相機拍攝的圖片或從照片庫中獲取的圖片的代碼。上傳發生和成功,該代碼執行後:Firebase圖片上傳成功完成,但圖片不在Firebase存儲中

// Return a promise to catch errors while loading image 
    getMedia(options, square, username): Promise<any> { 
    //this.storage.get('username').then((val) => {this.username = val; console.log(this.username + "  getting usern34433245555555ame")}); 

    // Get Image from ionic-native's built in camera plugin 
    return this.camera.getPicture(options) 
     .then((fileUri) => { 

     // op 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 this.crop.crop(fileUri, { quality: 10 }); 
     } else if (this.platform.is('android')) { 
      // Modify fileUri format, may not always be necessary 
      fileUri = 'file://' + fileUri; 

      /* Using cordova-plugin-crop starts here */ 
      return this.crop.crop(fileUri, { quality: 10 }); 
     } 
     }) 
     .then(newPath => { 
     console.log(newPath); 
     if(newPath) { 
      let fileName = newPath.substring(newPath.lastIndexOf("/") + 1, newPath.length); 
      let filePath = newPath.substring(0, newPath.lastIndexOf("/")); 
      this.file.readAsDataURL(filePath, fileName).then(data => { 
      //let strImage = data.replace(/^data:image\/[a-z]+;base64,/, ""); 
      //this.file.writeFile(this.file.tempDirectory, "image.jpg", strImage); 
      //let blob = dataURItoBlob(data); 
      var dataURL = data; 

      console.log(username + " this is passed usernameeeeeeeeee =="); 

       let image  : string = 'profilepicture.png', 
       storageRef : any, 
       parseUpload : any; 

       return new Promise((resolve, reject) => { 
       storageRef  = firebase.storage().ref('/profile/' + username + '/' + image); 
       parseUpload  = storageRef.putString(dataURL, 'data_url'); 

       console.log(username + "  username in promise !!!!!!"); 

       console.log("got to storageref after"); 
       parseUpload.on('state_changed', (_snapshot) => { 
        // We could log the progress here IF necessary 
        console.log('snapshot progess ' + _snapshot); 
        }, 
        (_err) => { 
        reject(_err); 
        console.log(_err.messsage); 
        }, 
        (success) => { 
        console.log(' was  a  suc cesssssss'); 
        resolve(parseUpload.snapshot); 
        }) 
       }).then(value => { 
        //this.af.list('/profile/' + self.username).push({ pic: image }); 
       }).catch(function(error) { 
        console.log(error.message); 
       }); 

      //let file 
      }); 
      } 
     }); 

    } 

console.log(username + " username in promise !!!!!!");控制檯輸出是正確的,我認爲這是使用了正確的storageRef

控制檯輸出的上傳是這樣的:

[20:35:56] console.log: Blue username in promise !!!!!! 
[20:35:56] console.log: got to storageref after 
[20:35:56] console.log: snapshot progess [object Object] 
[20:35:57] console.log: snapshot progess [object Object] 
[20:35:57] console.log: was a suc cesssssss 

但是,當我看着火力存儲,新的文件夾和圖像不存在。 Firebase存儲沒有變化。爲什麼它實際上不存儲在存儲中?

回答

0

storageRef = firebase.storage().ref('/profile/' + username + '/' + image);

應該是:

storageRef = firebase.storage().ref('/settings/' + username + '/' + image);

我一直在尋找在錯誤的文件夾上傳。

相關問題