将文件从Ruby On Rails上传到S3存储桶的问题

时间:2018-10-21 06:59:47

标签: ruby-on-rails amazon-web-services amazon-s3

我目前正在研究概念验证应用程序,该应用程序接受用户上传的文件并将其上传到S3存储桶。 但是,每当我尝试生成一个代表上传的上传模型时,都会出现以下一系列错误:

eli@eli-VirtualBox:~/upload_test$ rails g model Upload url name
eli@eli-VirtualBox:~/upload_test$ /var/lib/gems/2.5.0/gems/aws-partitions-1.105.0/lib/aws-partitions/endpoint_provider.rb:82:in `block in partition_matching_region': undefined method `match' for nil:NilClass (NoMethodError)
    from /var/lib/gems/2.5.0/gems/aws-partitions-1.105.0/lib/aws-partitions/endpoint_provider.rb:81:in `each'
    from /var/lib/gems/2.5.0/gems/aws-partitions-1.105.0/lib/aws-partitions/endpoint_provider.rb:81:in `find'
    from /var/lib/gems/2.5.0/gems/aws-partitions-1.105.0/lib/aws-partitions/endpoint_provider.rb:81:in `partition_matching_region'
    from /var/lib/gems/2.5.0/gems/aws-partitions-1.105.0/lib/aws-partitions/endpoint_provider.rb:70:in `get_partition'
    from /var/lib/gems/2.5.0/gems/aws-partitions-1.105.0/lib/aws-partitions/endpoint_provider.rb:23:in `signing_region'
    from /var/lib/gems/2.5.0/gems/aws-partitions-1.105.0/lib/aws-partitions/endpoint_provider.rb:99:in `signing_region'
    from /var/lib/gems/2.5.0/gems/aws-sdk-s3-1.21.0/lib/aws-sdk-s3/plugins/s3_signer.rb:20:in `block in <class:S3Signer>'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:70:in `call'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:205:in `block in resolve_defaults'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:57:in `each'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:57:in `each'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:204:in `resolve_defaults'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:200:in `value_at'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:189:in `block in resolve'
    from /usr/lib/ruby/2.5.0/set.rb:338:in `each_key'
    from /usr/lib/ruby/2.5.0/set.rb:338:in `each'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:189:in `resolve'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:177:in `apply_defaults'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/configuration.rb:150:in `build!'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/base.rb:62:in `build_config'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/base.rb:19:in `initialize'
    from /var/lib/gems/2.5.0/gems/aws-sdk-s3-1.21.0/lib/aws-sdk-s3/client.rb:233:in `initialize'
    from /var/lib/gems/2.5.0/gems/aws-sdk-core-3.32.0/lib/seahorse/client/base.rb:99:in `new'
    from /var/lib/gems/2.5.0/gems/aws-sdk-s3-1.21.0/lib/aws-sdk-s3/resource.rb:14:in `initialize'
    from /home/eli/upload_test/config/initializers/aws.rb:8:in `new'
    from /home/eli/upload_test/config/initializers/aws.rb:8:in `<main>'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `block in load'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:281:in `load'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:657:in `block in load_config_initializer'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/notifications.rb:170:in `instrument'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:656:in `load_config_initializer'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:613:in `each'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/engine.rb:613:in `block in <class:Engine>'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `instance_exec'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:32:in `run'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /usr/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
    from /usr/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /usr/lib/ruby/2.5.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    from /usr/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /usr/lib/ruby/2.5.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:50:in `each'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:50:in `tsort_each_child'
    from /usr/lib/ruby/2.5.0/tsort.rb:415:in `call'
    from /usr/lib/ruby/2.5.0/tsort.rb:415:in `each_strongly_connected_component_from'
    from /usr/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /usr/lib/ruby/2.5.0/tsort.rb:347:in `each'
    from /usr/lib/ruby/2.5.0/tsort.rb:347:in `call'
    from /usr/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
    from /usr/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
    from /usr/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/initializable.rb:60:in `run_initializers'
    from /var/lib/gems/2.5.0/gems/railties-5.2.1/lib/rails/application.rb:361:in `initialize!'
    from /home/eli/upload_test/config/environment.rb:10:in `<main>'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
    from /var/lib/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `block in require'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in `load_dependency'
    from /var/lib/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in `require'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /var/lib/gems/2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from -e:1:in `<main>'

有人知道这个问题可能是什么吗?如果需要,我可以发布相关的代码片段。

1 个答案:

答案 0 :(得分:1)

您似乎尚未配置区域。要配置区域,请设置AWS_REGION环境变量,或将其作为参数传递。例如:

key = OpenSSL::PKey::RSA.new(1024)
s3 = Aws::S3::Encryption::Client.new(encryption_key: key, region: "us-east-1") # or the region you are using