Maarten
Maarten

Reputation: 7308

NoSuchKey error for an existing object

I have my S3 account set up in Rails 3 like so:

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' 

But for some reason it says that my files do not exist. I have given 'Everyone' Open/Download permissions on the files in S3.

In the Rails console, for 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>'

What's wrong?

UPDATE: I noticed that in object.rb, the AWS S3 gem (v0.6.3) does the following:

bucket = Bucket.find(bucket_name(bucket), :marker => key.previous, :max_keys => 1)

where key is '/xml/BWBR0001821.xml', and key.previous is '/xml/BWBR0001821.xmk'... What the hell? This seems like a bug to me.

Upvotes: 1

Views: 1078

Answers (1)

Maarten
Maarten

Reputation: 7308

Found the error. Apparently, the find method gets confused when by the first forward slash. Using xml/BWBR0001821.xml as a file name works:

>> AWS::S3::S3Object.find('xml/BWBR0001821.xml', 'wetten')
#<AWS::S3::S3Object:0x49387284 '/wetten/xml/BWBR0001821.xml'>

Upvotes: 1

Related Questions