Deploying on Heroku - Images disappears after uplo

2019-02-21 04:59发布

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.

enter image description here

1条回答
欢心
2楼-- · 2019-02-21 05:45

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']
  }
}
查看更多
登录 后发表回答