Using Paperclip + heroku + s3 ... local uploads broken when pushed live
I am building a small website that has a fairly large amount of pictures > 100 for a small local group of people. If I upload files to s3 via paperclip on my local machine they work just fine, but when I push it to heroku those pics are then broken (aka pointing to the wrong location).
If I pull the live database from heroku (case where I upload photos to the app that is online, then pull the online database). Those images don't load in my local app.
Any ideas on how to get this working?
EDIT: Some more clarification on the problem: I have now set the path within the model like so
:path => "/public/system/:attachment/:style/:id.:extension"
And it now controls how the url looks when accessing S3. However my local machine outputs this as the image source:
bucket/Users/msencenb/Development/appname/public/system/pictures/7/thumb/overlook.jpg?2011
while the heroku app source looks like this:
bucket/app/public/system/pictures/7/thumb/overlook.jpg?2011
As you can see this is very similar except the local one injects the directory structure into the source path 开发者_运维技巧as well. How can I the source path with paperclip?
See this blog post:
http://codeglot.com/posts/68-upoading_pictures_to_apps_on_heroku
I've have multiple apps that use paperclip and s3. This is how I have it setup:
has_attached_file :picture,
:styles => {:large => "275x450>"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "appname/:attachment/:style/:id.:extension"
Make sure you replace your appname
with the name of your app. such as the subdomain you can access your app on heroku.
When you work on your local machine, the files are uploaded to S3 using the ids from your local database, and when you push to heroku, if you don't update the remote database with your local content, the references will be broken.
Try taking out the forward slash you have at the beginning of your path.
:path => "public/system/:attachment/:style/:id.:extension"
It shouldn't be taking the app path (Users/msencenb/Development/appname on local and app on Heroku) like that. Something is causing it and if taking the slash out doesnt work then try to investigate what else would be causing this.
精彩评论