问题
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