node.js createWriteStream doesn't create new file on Heroku

僤鯓⒐⒋嵵緔 提交于 2019-12-11 03:53:17

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/30491949/node-js-createwritestream-doesnt-create-new-file-on-heroku

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