node.js createWriteStream不会在Heroku上创建新文件 [英] node.js createWriteStream doesn't create new file on Heroku

查看:150
本文介绍了node.js createWriteStream不会在Heroku上创建新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码可以在运行node.js 0.12.0的本地主机上正常工作。该代码创建一个新文件,并从可读的数据中复制数据,但它不会在Heroku上创建新文件。

  var output = fs.createWriteStream('public / images / test / testfile.png'); 
readable.pipe(输出);

我认为这与权限有关,但是每当我更改文件夹的权限时 heroku运行bash ,然后 chmod -R 777 images / Heroku将其重置为其原始权限 drwx ------



可能这个问题是别的?



请注意,它在静默中失败,没有例外,日志中没有任何内容。

dyno的本地文件存储不是持久的(除了git repo文件显然),所以如果你写一个本地文件并且dyno重新启动,文件将会消失,如果你启动另一个dyno,它将无法看见文件。

heroku run bash 启动一个新的一次性dyno(可以在这里阅读:< a href =https://devcenter.heroku.com/articles/one-off-dynos =nofollow> https://devcenter.heroku.com/articles/one-off-dynos ) ,所以文件不会是ac如果你想让你的数据持久化,最好使用一些数据库或永久存储插件。


I have following code that works fine on my localhost running node.js 0.12.0. The code creates a new file, and copy data from readable, but it doesn't create new file on Heroku.

var output = fs.createWriteStream('public/images/test/testfile.png');
readable.pipe(output);

I thought it has something to do with the permission, but whenever I change the permission on the folder using heroku run bash and then chmod -R 777 images/ Heroku resets it back to its original permission which is drwx------.

So may be the problem is something else?

Please note that it fails silently, no exception, nothing in the log.

解决方案

In Heroku a dyno's local file storage is not persistent (besides the git repo files obviously), so if you write a local file and the dyno restarts the file will be gone, and if you start another dyno it won't be able to "see" the file.

heroku run bash starts a new "one-off" dyno (can read about it here: https://devcenter.heroku.com/articles/one-off-dynos), so the file will not be accessible that way.

If you want your data to persist, better use some database or persistent storage addon.

这篇关于node.js createWriteStream不会在Heroku上创建新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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