aws-s3 gem 和 right_aws gem 之间的 Rails 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'
...
谢谢!
for a new App I want to use paperclip to store Files to S3. I already have installed the aws-s3 gem for another app. That seems to cause some problems, because Paperclip should use right_aws but is trying to use the aws-s3 gem. But I don't want to remove the aws-s3 gem from my system. Is there a way to solve this conflict? Maybe by forcing paperclip to use right_aws? Or by changing the configuration?
My setup
# 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'
...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
哇,那速度真快。我通过使用 aws-s3 gem 解决了这个问题,因此将 enviroment.rb 更改为:
希望对某人有帮助!
Wow, that was fast. I solved the issue by just using the aws-s3 gem and therefore changing my enviroment.rb to read:
Hope that helps somebody!
不久前,亚马逊发布了官方 AWS SDK for Ruby。它与 S3 配合得很好,开箱即可支持美国、欧洲和日本的 S3 实例,并且维护良好。
我为 Paperclip 创建了一个名为 paperclip-aws 的存储模块,可与 AWS SDK 配合使用。
请随意使用它。我希望它会有所帮助。
Not long ago Amazon released official AWS SDK for Ruby. It works pretty well with S3, supports American, European and Japanese S3 instances from the box and well maintained.
I have created a storage module for Paperclip called paperclip-aws to works with AWS SDK.
Feel free to use it. I hope that it will help.
我也有这个问题。按特定顺序指定 gem 似乎对某些人有用:
在我的应用程序中,我还有一个插件 (backup_fu) 也指定
right_aws
,并且我还必须注释掉插件中的行:有谁知道为什么会出现这个问题吗?
编辑:在我的应用程序中,我根本不再需要 right_aws,然后在 backup_fu gem 中,我将 require 行更改为仅需要 right_aws(如果尚未加载)。我发现通过要求environment.rb中的gem,它导致了与aws-s3 gem的冲突。因此,现在 backup_fu 插件将在需要时加载它(通常仅在作为 rake 任务运行时),但不会在应用程序启动时加载。
I had this problem also. Specifying the gems in a certain order seems to work for some people:
In my app I also had a plugin (backup_fu) specifying
right_aws
as well, and I had to comment out the line in my plugin as well:Does anyone know why this is an issue?
EDIT: In my app I no longer require right_aws at all, and then in the backup_fu gem I changed the require line to only require right_aws if it's not already loaded. I found that by requiring the gem in environment.rb, it caused a conflict with the aws-s3 gem. So now the backup_fu plugin will load it if required (usually only when running as a rake task), but not when the app is started up.
这里的主要问题是 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 发送了一个拉取请求。
因此,您可以在捆绑包中使用我的 git 存储库来解决此问题:
gem 'right_http_connection', :git =>; “git://github.com/gammons/right_http_connection”
The main issue here is that aws-s3 redefines a method called
send_request_with_body_stream
.aws-s3's version has 4 arguments, and right_http_connection's has 5. Depending on load order, aws-s3 can redefine right_http_connection's version of that method.
I cloned right_http_connection and made a quick fix for this issue. I sent a pull request to right_http_connection.
Therefore you can use my git repo in your bundle to fix this issue:
gem 'right_http_connection', :git => "git://github.com/gammons/right_http_connection"