【问题标题】:How to not override images folder when 'git push heroku'?'git push heroku'时如何不覆盖图像文件夹?
【发布时间】:2018-02-02 02:19:10
【问题描述】:

我花了几个小时试图找到解决方案,但我什至不知道如何称呼它。我制作了一个 node.JS 应用程序,使用 'Heroku' 部署和 'MLab' 用于 MongoDB。

每个用户都可以上传图片,图片的url('~/img/{user_id}.jpg')存储在mongoDB中,图片的名字就是用户的id。

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

并在“ejs”页面上显示图像:

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

但是,每次我推送到 Heroku(每次我更新代码)时,“img”文件夹都会消失(提交会覆盖它)。

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

我制作了 .gitignore 文件

node_modules/
/public/img/

但它似乎不起作用,图像没有显示。

我可以以某种方式将我的更改推送到 Heroku 并保留“img”文件夹而不做任何更改吗?

【问题讨论】:

  • 每次推送到 Heroku 时,它都会重新部署应用程序(重新实例化它)。 Heroku 不是托管服务;传统意义上的。 @TGrif 为您提供了一个很好的方法。另一种选择是使用 AWS S3 等服务存储图像。

标签: node.js git mongodb express heroku


【解决方案1】:

heroku 上没有持久存储,所以不,你不能。

另一方面,您可以做的一件事是将图像存储在 MongoDB 上,因为您有一个 mLab 数据库。
例如,您可以使用 GridFS 来存储您的原始图像文件,以便它们独立于您的 heroku 代码应用程序而持续存在。

【讨论】:

    猜你喜欢
    • 2014-09-06
    • 2012-02-11
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多