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

发布于 2024-08-07 14:35:30 字数 1779 浏览 6 评论 0原文

对于新应用程序,我想使用回形针将文件存储到 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 技术交流群。

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

发布评论

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

评论(4

笑红尘 2024-08-14 14:35:30

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

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

希望对某人有帮助!

Wow, that was fast. I solved the issue by just using the aws-s3 gem and therefore changing my enviroment.rb to read:

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

Hope that helps somebody!

樱&纷飞 2024-08-14 14:35:30

不久前,亚马逊发布了官方 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.

罪#恶を代价 2024-08-14 14:35:30

我也有这个问题。按特定顺序指定 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 任务运行时),但不会在应用程序启动时加载。

I had this problem also. Specifying the gems in a certain order seems to work for some people:

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

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:

# 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

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.

野鹿林 2024-08-14 14:35:30

这里的主要问题是 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"

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