meteor write file on meteor.com

假如想象 提交于 2019-12-12 06:47:23

问题


I want to deploy a meteor app to meteor.com.

Unfortunately I have to write some tmp files to the public folder of meteor.

Example Code:

var fs = Npm.require('fs');
var filepath = "../../../../../public/resizing/tmp~";
fs.open(localpath, 'w', function(err,fd)
{
   if(err) throw "error opening file";
   fs.close(fd,function(){});
}

( ../../../../../public is the location of the meteor public folder after bundling! )

This works fine on my local machine, because I have write privileges inside the public folder. Is there a way how I can write to a tmp file in an app that is deployed to meteor?


回答1:


Most cloud providers don't allow access to file system, because this would put too much constraints on the architecture. Meteor.com is not different. For Meteor, there's also a problem of /public dir being precached by the engine, so every change to that folder would result in server being restarted (you can see that on your local machine as well).

Whatever you're trying to achieve, there are different ways. The most common ones are:

  • Use an external storage system, such as Amazon S3.
  • Simply, write the files you need as a new collection in the database. It's obvious how to do it for text files, but as easy for binary ones - just convert them to base64.



回答2:


Meteor allows people to deploy apps to meteor.com as a courtesy, but I agree that writing to the file system dynamically would be a security risk for them. You can package your app and deploy it to your own server somewhere if that's easier, but you might want to rewrite the app logic itself to keep that data somewhere other than the same location of your app (S3, for instance). I'm assuming you're trying to store images or something. If it's not, just use Meteor's data stores and keep it there.



来源:https://stackoverflow.com/questions/19961296/meteor-write-file-on-meteor-com

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