阅读CollectionFS文件从服务器的文件系统上meteor.com托管时 [英] Read CollectionFS file from server's filesystem when hosted on meteor.com
问题描述
我试着让用户上传一个txt文件,然后让他点击按钮分析,然后进行一些分析。
Im trying let the user Upload a txt file and then let him click a button "analyze" and then perform some analysis.
我的应用程序在本地工作,即时通讯使用FS.Collection和文件系统,但是我不得不部署到meteor.com几个问题。下面是我收集的:
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');
在本地而不是当我部署到meteor.com以上的作品,我看到类似这样的调试消息:错误:ENOENT,没有这样的文件或目录
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
所以,我不知道如何读取文件时,应用程序部署,你会怎么办呢?或者你认为我应该部署的应用程序,以Amazon EC2的?我怕部署到亚马逊和有同样的问题...
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...
推荐答案
使用HTTP下载一个通过collectionFS上载的文件的简单的例子。
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
}
});
请注意,您必须流星添加http
来获得访问HTTP包。
Note that you must meteor add http
to get access to the http package.
这篇关于阅读CollectionFS文件从服务器的文件系统上meteor.com托管时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!