Store image in database using rails paperclip plugin

妖精的绣舞 提交于 2019-11-30 05:09:56

问题


I have an application that uses the Paperclip plugin for image upload. Now that app should get deployed to an host(heroku) which has a read-only file system. Can I somehow tell paperclip to store the images in the database?


回答1:


Check out this sample app

http://patshaughnessy.net/2009/5/29/paperclip-sample-app-part-3-saving-file-attachments-in-a-database-blob-column

I guess this is exactly what you need.

HTH

PS: storing images in db is usually a bad idea, I am sure you can use paperclip with S3 / cloudfront ( as mentioned in the answers below )




回答2:


Heroku recommends storing file uploads on s3, and provides instructions on how to do so for several Rails file plugins.




回答3:


Rethink what you're doing. Storing images in the db is generally a bad idea. For more info, see here.

ry is right to point you towards S3. If nothing else, think of the cost: 500 MB of database space on Heroku is $50/month. On S3, it'll be 15 cents.




回答4:


Image serving from S3 is slow. Latencies of 0.5s to 2s are common, which means it should only be used for media assets.



来源:https://stackoverflow.com/questions/1596725/store-image-in-database-using-rails-paperclip-plugin

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