使用回形针 +赫罗库 + s3 ...本地上传在推送时损坏
我正在建立一个小型网站,其中有相当多的图片>当地一小群人 100 人。如果我通过本地计算机上的回形针将文件上传到 s3,它们工作得很好,但是当我将其推送到 heroku 时,这些图片就会损坏(又名指向错误的位置)。
如果我从heroku中提取实时数据库(我将照片上传到在线应用程序,然后提取在线数据库的情况)。这些图像不会加载到我的本地应用程序中。
关于如何让它发挥作用有什么想法吗?
编辑: 对这个问题的更多澄清:我现在已经在模型中设置了路径,如下所示
:path => "/public/system/:attachment/:style/:id.:extension"
,它现在控制访问 S3 时 url 的外观。然而,我的本地计算机将其输出为图像源:
bucket/Users/msencenb/Development/appname/public/system/pictures/7/thumb/overlook.jpg?2011
而heroku应用程序源看起来像这样:
bucket/app/public/system/pictures/7/thumb/overlook.jpg?2011
如您所见,这非常相似,除了本地计算机也将目录结构注入源路径中。如何用回形针找到源路径?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅此博文:
http://codeglot.com/posts/68-upoading_pictures_to_apps_on_heroku
我已经有多个使用回形针和 s3 的应用程序。我的设置方式如下:
确保将
appname
替换为应用程序的名称。例如您可以在 heroku 上访问您的应用程序的子域。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:
Make sure you replace your
appname
with the name of your app. such as the subdomain you can access your app on heroku.当您在本地计算机上工作时,文件将使用本地数据库中的 id 上传到 S3,当您推送到 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.
尝试去掉路径开头的正斜杠。
它不应该像这样采用应用程序路径(本地上的 Users/msencenb/Development/appname 和 Heroku 上的应用程序)。某些原因导致了这种情况,如果去掉斜线不起作用,那么尝试调查其他原因会导致这种情况。
Try taking out the forward slash you have at the beginning of your path.
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.