2017-10-03 4 views
1

Hochladen Was ich verwendeAngular/Firebase - Wie ein Bild, um die Größe vor

  • Angular
  • Firebase

Was ich versuche

zu erreichen
  • Hochladen eines Imag e Feuerbasis (bekam diese nach unten)

  • das Bild Ändern der Größe vor

Hochladen Wo ich bin stecken

  • zu Feuerbasis Speicher So kann ich erfolgreich ein Bild hochladen

  • Was ich vermeiden möchte, ist Benutzer hochladen Bilder größer als 300 x 300

Frage

  1. Wie kann ich sicherstellen, dass jedes Bild jemand uploads entsprechend der Größe verändert wird, so dass meine Lagerung/Kosten im Zusammenhang mit nicht erhöht werden 4000px Bildern?

Mein Upload Service

Unten ist, wie meine Komponente erfolgreich auf Firebase hochgeladen. Wenn jemand helfen kann, die Größe des Bildes zu ändern, bevor es hochgeladen wird, wäre ich außerordentlich dankbar!

uploadImage(upload: Upload) { 
    this._subscription = this.authService.user.subscribe(user => { 
     if (user) { 

     // Generate a new firebase key 
     let newPostKey = firebase.database().ref().child('albums').push().key; 


     // Create a reference to the firebase storage 
     this.imagePathString = 'thumbnail/' + newPostKey + '/thumbnails'; 

     const storageRef = firebase.storage().ref(); 
     const uploadTask = storageRef.child(this.imagePathString).put(upload.file); 

     // Upload task initiated - View progress and update real time database 
     uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, 
      (snapshot) => { 
      upload.progress = (uploadTask.snapshot.bytesTransferred/uploadTask.snapshot.totalBytes) * 100; 
      console.log(upload.progress); 
      }, 
      (error) => { 
      // upload failed 
      console.log(error) 
      }, 
     () => { 
      return undefined; 
      } 
     ); 
     } 
    }); 
    } 

Antwort

Verwandte Themen