且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Heroku数据库中存储图像最简单的方法是什么?

更新时间:2023-11-28 22:51:04

我鼓励你不要使用你的数据库来存储该大小的图像。

S3可以非常有效地备份,并且非常强化。从数据丢失的角度来看,它是安全的,然后开发postgres数据库的计划。



在这个例子中,成本方面也不是***的做法。虽然你是对的,但他们只强制行限制,我认为在开发数据库计划中存储大型图像(0.5 - 2mb)是不可取的。



最后,由于亚马逊的内部网络,从EC2(Heroku托管的地方)转移到S3的速度非常快。

知道这一点,我希望你能够重新思考您希望将这种大小的图像存储在数据库中。请参阅此问题,以便更深入地分析利弊。 。

还有开发中心文章

关于使用S3和Heroku。

We have a RoR 3.2 site on Heroku using their production tier PostgreSQL database.

Our site users occasionally upload images of 0.5 - 2MB in size. For different reasons we want to store those images in the database, rather than as files on S3 or similar.

If our site was image heavy, i.e. a Facebook clone, surely storing images in the db would not be a good thing.

Anyway, it is not, so here are some of the reasons for wanting to store a users images in the database:

  • Control over everything: S3 downtime and third party gems cannot break image handling/access to images.
  • Easy delete: If a user cancels his account, we can easily delete all associated images with that account through our rails models (relation dependencies).
  • Easier user data export: When a user wants to leave our site and take his data with him, we can more easily export his images rather than having to export from S3
  • Cost: Not a weighty argument, but since we're already paying for the database it will be cheaper than using S3 which costs (a small amount of) money.
  • Backups: Not a weighty argument, but a backup of our db would include everything associated with our site (except the RoR code, of course).

What is the easiest way to store images in the Heroku PostgreSQL database? Example code or link to a walk-through would be most welcome.

Thanks :)

I encourage you to not use your database to store images of that size.

S3 can be backed up very effectively, and is extremely hardened. From a data loss perspective, it's effectively safer then a development postgres database plan with Heroku.

The cost aspect is also not really best practice in this example. Although you're right they only enforce a row limit, I think it would be frowned upon to store large images (0.5 - 2mb) in the development database plan.

Finally, the speed of a transfer to S3 from EC2 (where Heroku is hosted) is very fast due to Amazon's internal networking.

Knowing that, I'd urge you to rethink your desire to store images of that size in a database. See this question for a more in depth analysis on the pros and cons.

There's also a dev center article about using S3 and Heroku.