当' git push heroku&#39 ;?时如何不覆盖图像文件夹?

时间:2018-02-01 17:47:48

标签: node.js git mongodb express heroku

我试图找到解决方案几个小时,但我甚至不知道怎么称呼它。我使用' Heroku'做了一个node.JS应用程序。部署和'MLab'对于MongoDB。

每个用户都可以上传图片,图片网址('〜/ img / {user_id} .jpg')存储在mongoDB中,图片名称是用户的ID。

user.imgUrl = __dirname+'/../public/img/users_avatars/'+user.id+'.jpg';

并在' ejs'上显示图片。页:

<img src="<%=user.imgUrl%>" alt="avatar">

但是,每次我推送到Heroku(每次我更新代码)时,&#34; img&#34;文件夹消失(提交覆盖它)。

git add .
git commit -m "some_message"
git push heroku

我制作了.gitignore文件

node_modules/
/public/img/

但它似乎确实有效,图像显示出来。

我可以以某种方式将我的更改推送到Heroku并保持&#39; img&#39;文件夹没有任何变化?

1 个答案:

答案 0 :(得分:1)

There is no persistent storage on heroku, so no, you can't.

One thing you can do, on the other hand, is to store your images on MongoDB since you have a mLab database.
For example, you could use GridFS to store your raw image files, so that they persist independently of your heroku code application.