heroku+s3+回形针

发布于 2024-10-30 15:43:37 字数 624 浏览 1 评论 0原文

伙计们, 我在使用 s3 时遇到问题...我正在尝试以这种方式配置 s3 以使用回形针:

has_attached_file :photo,

:storage => :s3,

:bucket => 'gallerybucket',

:styles => { :small => ["150", :png], :large => ["500", :png], :very_large => ['750x500>', :png] },


:path => ":rails_root/public/images/:class/:attachment/:id/:style_:basename.png",


:url => "/images/:class/:attachment/:id/:style_:basename.png",


:default_url => "/images/sem_imagem.gif",

:s3_credentials => {
  :access_key_id => ENV['ac'],
  :secret_access_key => ENV['sc']
}

但它总是向我显示此错误。我不明白我在这里做错了什么。是否缺少某些配置?

Guys,
I'm having a problem with s3...I'm trying to configure the s3 this way to work with the paperclip:

has_attached_file :photo,

:storage => :s3,

:bucket => 'gallerybucket',

:styles => { :small => ["150", :png], :large => ["500", :png], :very_large => ['750x500>', :png] },


:path => ":rails_root/public/images/:class/:attachment/:id/:style_:basename.png",


:url => "/images/:class/:attachment/:id/:style_:basename.png",


:default_url => "/images/sem_imagem.gif",

:s3_credentials => {
  :access_key_id => ENV['ac'],
  :secret_access_key => ENV['sc']
}

but it always shows me this error. I don't understand what I'm doing wrong here. Is there some configuration missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁绊已千年 2024-11-06 15:43:37

如果您还没有 s3 帐户,请在此处获取一个:

http://aws.amazon.com/s3 /

您需要将其添加到您的联系人模型中:

app/models/contact.rb

  has_attached_file :picture, 
                     :styles => {:large => "275x450>"},
                     :storage => :s3, 
                     :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                     :path => "appname/:attachment/:style/:id.:extension"

确保您的 appname 是您在 Heroku 上的 Rails 应用程序名称。并确保将图片重命名为您为图片命名的名称。

然后你需要一个位于 config/s3.yml 中的配置文件。

development:
  bucket: bucked_name
  access_key_id: key
  secret_access_key: secret

production:
  bucket: bucked_name
  access_key_id: key
  secret_access_key: secret

确保您获得的密钥和秘密正确。

在您的 gem 文件中,确保安装了这些 gem:

gem "aws-s3", :require => "aws/s3"
gem "paperclip"

If you don't have an s3 account already go get one here:

http://aws.amazon.com/s3/

You need to add this to your contact model:

app/models/contact.rb

  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 appname is your rails app name on heroku. And make sure you rename picture to whatever you have named your picture.

Then you need a config file in config/s3.yml.

development:
  bucket: bucked_name
  access_key_id: key
  secret_access_key: secret

production:
  bucket: bucked_name
  access_key_id: key
  secret_access_key: secret

Make sure you get the key and secret correct.

In your gem file make sure you have these gems install :

gem "aws-s3", :require => "aws/s3"
gem "paperclip"
荆棘i 2024-11-06 15:43:37

听起来好像您将变量添加到了 heroku 帐户,但是您是否将它们添加到了 .bashrc 文件中?

export ACCESS_KEY_ID='acckeyid'
export SECRET_ACCESS_KEY='secacckey'

然后在您的代码中:

:s3_credentials => {
  :access_key_id => ENV['ACCESS_KEY_ID'],
  :secret_access_key => ENV['SECRET_ACCESS_KEY']
}

我有一个 博客文章也谈到了这一点。

Sounds like you added the variables to you heroku account, but did you add them to your .bashrc file?

export ACCESS_KEY_ID='acckeyid'
export SECRET_ACCESS_KEY='secacckey'

Then in your code:

:s3_credentials => {
  :access_key_id => ENV['ACCESS_KEY_ID'],
  :secret_access_key => ENV['SECRET_ACCESS_KEY']
}

I have a blog post I wrote that talks about this a little as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文