我在Rails 3中设置了我的S3帐户,如下所示:
AWS::S3::DEFAULT_HOST.replace "s3-eu-west-1.amazonaws.com"
#Set up AWS S3
AWS::S3::Base.establish_connection!(
:access_key_id => 'itsa',
:secret_access_key => 'secret'
)
BUCKET='wetten'
但由于某种原因,它说我的文件不存在。我已经为S3中的文件提供了“Everyone”打开/下载权限。
在Rails控制台中,this file:
>> AWS::S3::S3Object.exists?('/xml/BWBR0001821.xml', 'wetten')
true
>> AWS::S3::S3Object.find('/xml/BWBR0001821.xml', 'wetten')
AWS::S3::NoSuchKey: No such key `/xml/BWBR0001821.xml'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/aws-s3-0.6.3/lib/aws/s3/object.rb:177:in `find'
from (irb):11
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from C:/Users/Maarten/RubymineProjects/wetten-api/script/rails:6:in `require'
from C:/Users/Maarten/RubymineProjects/wetten-api/script/rails:6:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
怎么了?
更新:我注意到在object.rb中,AWS S3 gem(v0.6.3)执行以下操作:
bucket = Bucket.find(bucket_name(bucket), :marker => key.previous, :max_keys => 1)
其中key
为'/xml/BWBR0001821.xml'
,key.previous
为'/xml/BWBR0001821.xmk'
......到底是什么?这对我来说似乎是个错误。
答案 0 :(得分:1)
发现错误。显然,当通过第一个正斜杠时,find方法会混淆。使用xml/BWBR0001821.xml
作为文件名可以使用:
>> AWS::S3::S3Object.find('xml/BWBR0001821.xml', 'wetten')
#<AWS::S3::S3Object:0x49387284 '/wetten/xml/BWBR0001821.xml'>