在meteor.com上托管时,从服务器的文件系统中读取CollectionFS文件

时间:2015-09-23 19:58:16

标签: meteor amazon-ec2 collectionfs

我试着让用户上传一个txt文件然后让他点击一个按钮"分析"然后进行一些分析。

我让应用程序在本地工作,我正在使用FS.Collection和FileSystem但是我在部署到meteor.com时遇到了一些问题。这是我的收藏:

FS.debug = true;

Uploads = new FS.Collection('uploads', {
    stores: [new FS.Store.FileSystem('uploads')]
});

以下是我尝试阅读上传文件的方法:

var fs = Npm.require('fs');
var readedFile = fs.readFileSync(process.env.PWD+'/.meteor/local/cfs/files/uploads/+file.copies.uploads.key, 'utf-8');

上述工作在本地,但在我部署到meteor.com之后,在调试消息中,我看到这样的内容:Error: ENOENT, no such file or directory

所以我不知道在部署应用程序时如何阅读文件,你会怎么做?或者你认为我应该将应用程序部署到Amazon EC2?我害怕部署到亚马逊并遇到同样的问题...

2 个答案:

答案 0 :(得分:3)

使用http下载通过collectionFS上传的文件的简短示例。

var file = Uploads.findOne({ _id: myId }); // or however you find it
  HTTP.get(file.url(),function(err,result){
    // this will be async obviously
    if ( err ) console.log("Error "+err+" downloading file"+myId);
    else {
      var content = result.content; // the contents of the file
      // now do something with it
    }
  });

请注意,您必须meteor add http才能访问http包。

答案 1 :(得分:0)

这可能是你想要的包裹:

https://github.com/tomitrescak/meteor-uploads

它也有一个很好的用户界面,比FSCollection麻烦得多。