流星在meteor.com上写入文件 [英] meteor write file on meteor.com

查看:96
本文介绍了流星在meteor.com上写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将meteor应用程序部署到meteor.com.

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

不幸的是,我必须将一些tmp文件写入流星的公用文件夹中.

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

示例代码:

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是捆绑后流星公用文件夹的位置!)

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

这在我的本地计算机上可以正常工作,因为我在公用文件夹内具有写权限.有没有一种方法可以在部署到流星的应用程序中写入tmp文件?

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?

推荐答案

大多数云提供商都不允许访问文件系统,因为这会给体系结构带来太多限制. Meteor.com也不不同. 对于Meteor,引擎还存在/public dir预先缓存的问题,因此对该文件夹的每次更改都会导致服务器重新启动(您也可以在本地计算机上看到它).

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:

  • 使用外部存储系统,例如Amazon S3.
  • 只需将所需的文件作为新集合写入数据库中.对于文本文件来说,这样做是显而易见的,但对于二进制文件来说,却很容易-只需将它们转换为base64.

这篇关于流星在meteor.com上写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆