Deploying on Heroku - Images disappears after upload

别说谁变了你拦得住时间么 提交于 2019-12-30 17:09:24

问题


I deployed an application on Heroku which I wrote on Ruby on Rails. It is a movie review app.

I am able to upload images from my computer, to the web app online. Everything else works as per my expectations.

The images disappear after a day. My requirement is to have the image continue to render.

I am using Paperclip gem from rails. This only happens on the deployed version and not on localhost.


回答1:


The default upload location on Heroku is into temporary storage. This is because you will get a different web worker each time you deploy.

You need to use S3 or another location to store your files. Luckily this is well documented for Paperclip on Heroku.

The main configuration difference is this. Add gem 'aws-sdk' to your Gemfile and then adjust your config file in config/environments/production.rb:

config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['S3_BUCKET_NAME'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}


来源:https://stackoverflow.com/questions/32527103/deploying-on-heroku-images-disappears-after-upload

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