【问题标题】:Meteor FS.Collection access collection on serverMeteor FS.Collection 访问服务器上的集合
【发布时间】:2016-05-26 19:00:11
【问题描述】:

我正在使用 FS.Collection 将短视频文件上传到服务器上,然后将其作为电子邮件附件发送。

在服务器上插入集合可以工作,我可以在客户端访问集合项,也可以直接使用文件 URL 的路径进行流式传输 - localhost:3000/cfs/files/videos/{{item_id}}

我想知道如何访问服务器上的集合。我想以以下形式发送带有附件的电子邮件,并且需要访问服务器上文件和文件名的路径。我试着做:

Email.send({
  to: to,
  from: from,
  subject: subject,
  text: text,
  attachments:[{fileName:"video.mp4", filePath:"/cfs/files/videos/{{item_id}}"}]
});

它在电子邮件中显示附件视频播放器,但带有错误消息,所以我认为我没有正确访问文件。

我的 Collection.js 很简单:

var videoStore = new FS.Store.GridFS("videos");

Videos = new FS.Collection("videos", {
  stores: [videoStore]
});

【问题讨论】:

    标签: node.js meteor fs


    【解决方案1】:

    您不能通过collectionFS 的filePath 使用附件。 “/cfs/files/videos/{{item_id}}”是虚拟路径,即/cfs/files/videos中不存在文件,也没有文件夹'/cfs/files/videos'。

    您可以改用 http 路径:

    var ROOT_URL = process.env.ROOT_URL;
    var rootUrl;
    if (ROOT_URL.indexOf('/', ROOT_URL.length - 1) != -1) {
        rootUrl = ROOT_URL.substring(0, ROOT_URL.length - 1);
    } else {
        rootUrl = ROOT_URL;
    }
    
    var attachments = [];
    attachment = {
        fileName: fileName(url),
        filePath: rootUrl + "/cfs/files/videos/{{item_id}}"
    };
    attachments.push(attachment);
    
    Email.send({
        to: to,
        from: from,
        subject: subject,
        text: text,
        attachments: attachments
    });
    

    【讨论】:

      猜你喜欢
      • 2016-01-13
      • 2016-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 2018-02-03
      相关资源
      最近更新 更多