【问题标题】:Get image url in Meteor method在 Meteor 方法中获取图像 url
【发布时间】:2016-08-05 05:47:41
【问题描述】:

我似乎找不到任何文档来解释如何将上传的 collectionFS 图像的 filenamefilepath 导入到我的流星方法中。

我可以使用helpers 在客户端获取图像 URL 没有问题,但我似乎无法弄清楚如何将附加图像的文件名和文件路径发送到我的方法。

方法 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);
}
});

控制器 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
              }
            );
          };

【问题讨论】:

    标签: meteor angular-meteor collectionfs


    【解决方案1】:

    您可以使用插入回调来获取这些信息:

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

    【讨论】:

      猜你喜欢
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 2012-12-02
      • 1970-01-01
      • 2015-05-07
      • 2021-10-13
      • 2012-10-22
      相关资源
      最近更新 更多