0
我的教程在這裏以下內容:http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpRuby.html 瞭解使用Ruby上傳文件S3,我寫了這個:得到AWS ::錯誤:: MissingRegionError同時使用Ruby來上傳文件到S3
require 'aws-sdk'
s3 = Aws::S3::Client.new(
access_key_id: '.......',
secret_access_key: '........'
)
s3 = Aws::S3::Resource.new(region:'us-east-1')
obj = s3.bucket('aws-adms-whitelisting-rules').object('test')
obj.upload_file('~/Desktop/ruby/test.rb')
但得到以下錯誤:
/Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.10.7/lib/aws-sdk-core/plugins/regional_endpoint.rb:34:in `after_initialize': missing region; use :region option or export region name to ENV['AWS_REGION'] (Aws::Errors::MissingRegionError)
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.10.7/lib/seahorse/client/base.rb:84:in `block in after_initialize'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.10.7/lib/seahorse/client/base.rb:83:in `each'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.10.7/lib/seahorse/client/base.rb:83:in `after_initialize'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.10.7/lib/seahorse/client/base.rb:21:in `initialize'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-core-2.10.7/lib/seahorse/client/base.rb:105:in `new'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-resources-2.10.7/lib/aws-sdk-resources/resource.rb:169:in `extract_client'
from /Library/Ruby/Gems/2.0.0/gems/aws-sdk-resources-2.10.7/lib/aws-sdk-resources/resource.rb:15:in `initialize'
from test.rb:35:in `new'
from test.rb:35:in `<main>'
你能告訴我一個前進的道路嗎?謝謝
感謝的答案,但我得到了同樣的錯誤 – user8142520
我相信'AWS :: S3 :: Client'對象必須被傳遞作爲關鍵字參數傳遞給' Aws :: S3 :: Resource「,因爲'#initialize'只接受選項散列。 – dlachasse
@dlachasse,抓住你是對的。我編輯了我的答案。嘗試用哈希初始化資源,讓我知道如果這有效。 – treiff