2016-04-13 4 views
0

Ich kann nicht scheinen, um eine Dokumentation zu finden, die erklärt, wie ich die filename und filepath eines hochgeladenen CollectionFS-Bildes in meine Meteor-Methode bekommen kann.Get Bild URL in Meteor Methode

Ich bin in der Lage, die Image-URL auf der Client-Seite kein Problem mit helpers zu bekommen, aber ich kann nicht herausfinden, wie ich den Dateinamen und den Dateipfad des angehängten Bildes an meine Methode senden kann.

Methode JS

Meteor.methods({ 
addQuote: function(data) { 
    check(data, Object); 

    var attachments = []; 
    var html = html; 

    // need to get the filename and filepath from collectionFS 
    // I would then have the data go here 
    attachments.push({filename: , filePath: }); 

    this.unblock(); 

    var email = { 
    from: data.contactEmail, 
    to:  Meteor.settings.contactForm.emailTo, 
    subject: Meteor.settings.contactForm.quoteSubject, 
    html: html, 
    attachmentOptions: attachments 
    }; 

    EmailAtt.send(email); 
} 
}); 

-Controller JS

 function ($scope, $reactive, $meteor) { 
      $reactive(this).attach($scope); 

      this.user = {}; 


      this.helpers({ 
      images:() => { 
       return Images.find({}); 
      } 
      }); 

      this.subscribe('images'); 

      this.addNewSubscriber = function() { 


      // Uploads the Image to Collection 
      if(File.length > 0) { 
       Images.insert(this.user.contactAttachment); 
       console.log(this.user.contactAttachment); 
      } 

      // This is the variable I use to push to my method 
      // I image I need to push the filename and filepath also 
      // I am unsure how to access that information in the controller. 
      var data = ({ 
       contactEmail: this.user.contactEmail, 
       contactName: this.user.contactName, 
       contactPhone: this.user.contactPhone, 
       contactMessage: this.user.contactMessage 
      }); 

      // This will push the data to my meteor method "addQuote" 
      $meteor.call('addQuote', data).then(
       function(data){ 
       // Show Success 
       }, 
       function(err) { 
       // Show Error 
       } 
      ); 
      }; 

Antwort

0

können Sie den Einsatz Rückruf verwenden diese Informationen zu erhalten:

Images.insert(fsFile, function (error, fileObj) 
{ 
     if (error) console.log(error); 
     else 
     { 
      console.log(fileObj); 
      //Use fileObj.url({brokenIsFine: true}); to get the url 
     }       
});