Read CollectionFS file from server's filesystem when hosted on meteor.com

↘锁芯ラ 提交于 2019-12-13 19:17:57

问题


Im trying let the user Upload a txt file and then let him click a button "analyze" and then perform some analysis.

I have the app working locally, Im using FS.Collection and FileSystem however I had several problems deploying to meteor.com. Here is my collection:

FS.debug = true;

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

and here is how I try to read the uploaded file:

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

The above works in local but not after I deploy to meteor.com, in the debug messages I see something like this: Error: ENOENT, no such file or directory

So I do not know how to read the file when the app is deployed, how would you do it?, or do you think I should deploy the app to Amazon EC2? Im afraid to deploy to amazon and have the same problem...


回答1:


Short example of using http to download a file that was uploaded via 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
    }
  });

Note that you must meteor add http to get access to the http package.




回答2:


This is probably the package you want:

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

it has a nice UI too and much less trouble than FSCollection.



来源:https://stackoverflow.com/questions/32748427/read-collectionfs-file-from-servers-filesystem-when-hosted-on-meteor-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!