在aws-s3 gem和right_aws gem之间的Rails Paperclip冲突。 怎么解决?

对于新的应用程序,我想使用paperclip将文件存储到S3。 我已经为另一个应用程序安装了aws-s3 gem。 这似乎会导致一些问题,因为Paperclip应该使用right_aws但是试图使用aws-s3 gem。 但我不想从我的系统中删除aws-s3 gem。 有没有办法解决这个冲突? 也许通过强制回形针使用right_aws? 或者通过更改配置?

我的设置

# enviroment.rb config.gem 'right_aws' # my model with the attachment has_attached_file :thumbnail, :styles => { :thumb => "160x120>" }, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/amazons3.yml", :path => ":provider/:attachment/:id_:style.:extension" # config/amazons3.yml development: bucket: bucketname access_key_id: secret secret_access_key: secret test: bucket: bucketname access_key_id: secret secret_access_key: secret production: bucket: bucketname access_key_id: secret secret_access_key: secret # The Error in the console ArgumentError: wrong number of arguments (5 for 4) from /Library/Ruby/Gems/1.8/gems/right_http_connection-1.2.4/lib/net_fix.rb:85:in `send_request_with_body_stream' from /Library/Ruby/Gems/1.8/gems/right_http_connection-1.2.4/lib/net_fix.rb:85:in `exec' from /Library/Ruby/Gems/1.8/gems/right_http_connection-1.2.4/lib/net_fix.rb:144:in `request' from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/connection.rb:45:in `request' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start' from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/connection.rb:52:in `request' from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:69:in `request' from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:in `put' from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/object.rb:241:in `store' ... 

谢谢!

哇,那很快。 我通过使用aws-s3 gem解决了这个问题,因此将我的enviroment.rb更改为:

 #config.gem 'right_aws' config.gem "aws-s3", :version => ">= 0.6.2", :lib => "aws/s3" 

希望能帮到别人!

不久前,亚马逊发布了适用于Ruby的官方AWS SDK 。 它适用于S3,支持美国,欧洲和日本的S3实例,并且维护良好。

我已经为Paperclip创建了一个名为paperclip-aws的存储模块,可以与AWS SDK一起使用。

随意使用它。 我希望它会有所帮助。

我也有这个问题。 以某种顺序指定gem似乎适用于某些人:

 config.gem "aws-s3", :lib => "aws/s3", :version => '>= 0.6.2' config.gem "paperclip", :version => '>= 2.3.1.1' # config.gem "right_aws" 

在我的应用程序中,我也有一个插件(backup_fu)指定right_aws ,我也必须在我的插件中注释掉该行:

 # backup_fu.rb require 'yaml' require 'active_support' require 'mime/types' require 'right_aws' unless defined?(RightAws) require 'erb' class BackupFuConfigError < StandardError; end class S3ConnectError < StandardError; end class BackupFu # etc... end 

有谁知道为什么这是一个问题?

编辑:在我的应用程序中,我不再需要right_aws,然后在backup_fu gem中,我将require行更改为仅需要right_aws(如果尚未加载)。 我发现通过在environment.rb中要求gem,它引起了与aws-s3 gem的冲突。 所以现在backup_fu插件会在需要时加载它(通常只在作为rake任务运行时),而不是在应用程序启动时加载。

这里的主要问题是aws-s3重新定义了一个名为send_request_with_body_stream的方法。

aws-s3的版本有4个参数,而right_http_connection有5个。根据加载顺序,aws-s3可以重新定义right_http_connection的该方法的版本。

我克隆了right_http_connection并快速解决了这个问题。 我向right_http_connection发送了一个pull请求。

因此,您可以在捆绑中使用我的git repo来解决此问题:

gem 'right_http_connection', :git => "git://github.com/gammons/right_http_connection"