2017-09-01 2 views
0

Ich habe diesen Code, der ein Bild hochlädt, das mit der Kamera aufgenommen oder aus der Fotobibliothek abgerufen wurde. Der Upload geschieht und es gelingt ihm, nachdem dieser Code ausgeführt:Firebase-Image-Upload wird erfolgreich abgeschlossen, aber das Image befindet sich nicht im Firebase-Speicher

// 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 
      }); 
      } 
     }); 

    } 

Die Konsolenausgabe für console.log(username + " username in promise !!!!!!"); richtig ist, und ich glaube, die richtige storageRef verwendet wird.

Die Konsolenausgabe für den Upload ist dies:

[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 

Allerdings, wenn ich bei Feuerbasis Lagerung aussehen, der neue Ordner und Bild nicht da ist. Es gibt keine Änderungen am Firebase-Speicher. Warum speichert es nicht wirklich im Speicher?

Antwort

0

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

wurde sein soll:

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

Ich war für den Upload in den falschen Ordner suchen.

Verwandte Themen