【问题标题】:Rails paperclip with s3 - Invalid argument带有 s3 的 Rails 回形针 - 参数无效
【发布时间】:2012-02-20 15:52:02
【问题描述】:

我使用 Paperclip 设置了一个应用程序来解决用户头像的问题。我想在亚马逊 s3 上存储文件。我找不到这个问题的解决方案,所以最后我决定在这里问:

这是用户模型中的连接设置:

has_attached_file :avatar, 
:styles => { :small => "150x150#", :medium => "300x300#" },
:storage => :s3,
:s3_credentials => Rails.root.join('config/s3.yml')

那么这里是s3.yml文件:

bucket: sghub      
access_key_id: ###
secret_access_key: #####

当然在我的 gemfile 中我已经添加了:

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

应用程序部署在 Heroku 上,所以我从 heroku logs 命令得到的错误是这样的:

2012-02-20T07:13:58+00:00 app[web.1]: AWS::S3::PermanentRedirect (The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.)

同样在开发模式下,错误页面如下:

Errno::EINVAL in UsersController#update
Invalid argument

此外,文件似乎没有在 s3 上上传,因为它们在我的存储桶的管理控制台中不可见。我现在几乎不知道,因为我试图设置所有教程和文档中的所有内容。有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails amazon-s3 paperclip


    【解决方案1】:

    :bucket 选项应位于选项哈希中的 :s3_credentials 键之外。让它看起来像这样:

    has_attached_file :avatar, 
        :styles         => { :small => "150x150#", :medium => "300x300#" },
        :storage        => :s3,
        :s3_credentials => Rails.root.join('config/s3.yml')
        :bucket         => 'sghub'

    并从config/s3.yml 中删除bucket

    这里是文档:http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3

    【讨论】:

    • 我认为问题出在欧洲 Amazon s3 服务器的配置上,因为在回形针中默认是美国服务器。否则,您的提示帮助我找到了答案。非常感谢!
    猜你喜欢
    • 2016-06-26
    • 2017-04-24
    • 1970-01-01
    • 2014-10-13
    • 2018-06-13
    • 2016-12-11
    • 2011-03-21
    • 1970-01-01
    • 2015-08-05
    相关资源
    最近更新 更多