在Heroku数据库中存储图像最简单的方法是什么? [英] Easiest way to store images in database on Heroku?

查看:128
本文介绍了在Heroku数据库中存储图像最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Heroku上有一个RoR 3.2站点,使用他们的生产级PostgreSQL数据库。

我们的网站用户偶尔会上传0.5至2MB的图片。出于不同的原因,我们希望将这些图像存储在数据库中,而不是作为S3或类似文件。



如果我们的网站形象很重,也就是Facebook克隆,肯定会在数据库中存储图像不是一件好事。



无论如何,它不是,所以这里有一些原因希望将用户图像存储在数据库中:


  • 控制一切:S3停机时间和第三方宝石不能破坏图像处理/图像访问。

  • 轻松删除:如果用户取消了他的帐户,我们可以通过我们的导轨模型(关系依赖项)轻松删除所有与该帐户关联的图片。 更简单的用户数据导出:用户想要离开我们的网站,并与他的数据,我们可以更容易地出口他的形象,而不是必须从S3出口

  • 成本:不是一个重要的论点,但因为我们已经为数据库支付了费用,比使用S3(花费少量)的费用便宜ney。

  • 备份:不是一个很重要的参数,但是我们数据库的备份将包括与我们网站相关的所有内容(当然,除RoR代码外)。 b


在Heroku PostgreSQL数据库中存储图像的最简单方法是什么?示例代码或链接到演练将是最受欢迎的。



感谢:)

解决方案

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

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.

这篇关于在Heroku数据库中存储图像最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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