aws s3 回形针和 Rails 3.0 错误
首先非常感谢您花时间阅读我的问题。谢谢你!看来我在我的网络应用程序上实施 aws s3 时遇到了问题。我在 heroku 上部署了一个 ROR 应用程序,我希望允许用户将个人资料图片上传到他们的个人资料中。
我已经安装了 imagemagick 和回形针来处理附件。然后有人告诉我,heroku 不接受上传,我需要订阅 aws-s3。这是有道理的。因此,我注册了 aws 并将以下代码添加到我的项目中:
user.rb (model)
has_attached_file :avatar,
:styles => {:small => "70x70>"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style/:basename.:extension"
validates_attachment_size :avatar, :less_than => 1.megabytes
validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png']
s3.yml (文件位于 config 文件夹中) 注意:所有这些存储桶都存在于我的 aws-s3
development:
bucket: my_avatar-dev
access_key_id: amazonaccesskey
secret_access_key: amazon_secret_access_key
test:
bucket: myapp_avatar-test
access_key_id: amazonaccesskey
secret_access_key: amazon_secret_access_key
production:
bucket: myapp_avatar-pro
access_key_id: amazonaccesskey
secret_access_key: amazon_secret_access_key
gemfile
gem 'aws-s3'
中当我在开发环境(本地主机)中运行应用程序,一切正常...我检查了AWS,我的上传出现在那里;但是,当我将应用程序部署到 heroku 时,它就崩溃了。详细来说,应用程序会加载登录屏幕,但一旦用户登录,应用程序就会中断并重定向到错误 500 页面:“我们很抱歉,但出了点问题。我们已收到有关此问题的通知”我们很快就会看一下它。”
当我隐藏以下代码(并将 :path 替换为其他值)并重新部署时...应用程序会加载,但显然它缺少它的功能需要重定向到 aws-s3。
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style/:basename.:extension"
正如我提到的,我对 Rails 还很陌生......所以我不确定我做错了什么。我是否应该将 s3.yml 链接到其他地方、路线或其他东西?也许这是我在部署时需要做的事情?我要感谢任何可以帮助我的人,并且感谢您抽出宝贵的时间!
First off thanks so much for taking the time to read my question. Thank you! It appears that i'm having trouble implementing aws s3 on my webapp. I have a ROR app deployed o heroku and I'd like to allow users to upload a profile picture to their profile.
I've installed imagemagick and paperclip to handle the attachments. Then someone informed me that heroku does not accept uploads and that I'll need to subscribe to aws-s3. That made sense. So I signed up for aws and added the following code to my project:
user.rb (model)
has_attached_file :avatar,
:styles => {:small => "70x70>"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style/:basename.:extension"
validates_attachment_size :avatar, :less_than => 1.megabytes
validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png']
s3.yml (file is located in config folder) note: all of these buckets exist on my aws-s3
development:
bucket: my_avatar-dev
access_key_id: amazonaccesskey
secret_access_key: amazon_secret_access_key
test:
bucket: myapp_avatar-test
access_key_id: amazonaccesskey
secret_access_key: amazon_secret_access_key
production:
bucket: myapp_avatar-pro
access_key_id: amazonaccesskey
secret_access_key: amazon_secret_access_key
gemfile
gem 'aws-s3'
When I run the application in the development environment (localhost) everything functions properly... I checked AWS and my uploads appear there; however, when I deploy my app to heroku it breaks. To elaborate, the app loads the sign-in screen but as soon as a user signs in, the application breaks and redirects to the error 500 page: "We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly."
When I hide the following code (and replace :path with some other value) and re-deploy... the app loads, but obviously it lacks the functionality it needs to redirect to aws-s3.
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style/:basename.:extension"
As I mentioned, I'm pretty new to rails... so I'm not sure what I'm doing wrong. Was I supposed to link s3.yml somewhere else, a route or something? Maybe it's something that I need to do while deploying? I'd like to thank anyone who can help me, and I am thankful for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论