title: AWS::S3::Errors::NoSuchKey: No Such Key error
body: <p>I'm trying to create a method that deletes files on an S3 instance, but I am getting a <code>AWS::S3::Errors::NoSuchKey: No Such Key</code> error when I try to call <code>.head</code> or .<code>read</code> on an object.</p>
  
  <h3>app/models/file_item.rb</h3>
  
  <pre><code>def thumbnail
      {
        exists: thumbnailable?,
        small: "http://#{bucket}.s3.amazonaws.com/images/#{id}/small_thumb.png",
        large: "http://#{bucket}.s3.amazonaws.com/images/#{id}/large_thumb.png"
      }
  end 
  </code></pre>
  
  <h3>lib/adapters/amazons3/accessor.rb</h3>
  
  <pre><code>module Adapters
    module AmazonS3
      class Accessor
        S3_BUCKET =  AWS::S3.new.buckets[ENV['AMAZON_BUCKET']]
  
        ...
  
        def self.delete_file(thumbnail)
          prefix_pattern = %r{http://[MY-S3-HOST]-[a-z]+.s3.amazonaws.com/}
          small_path = thumbnail[:small].sub(prefix_pattern, '')
          large_path = thumbnail[:large].sub(prefix_pattern, '')
          small = S3_BUCKET.objects[small_path]
          large = S3_BUCKET.objects[large_path]
          binding.pry
          S3_BUCKET.objects.delete([small, large])
        end
      end
    end
  end
  </code></pre>
  
  <h3>example url1</h3>
  
  <pre><code>"http://projectname-staging.s3.amazonaws.com/images/994/small_thumb.png"
  </code></pre>
  
  <h3>example url2</h3>
  
  <pre><code>"http://projectname-production.s3.amazonaws.com/images/994/large_thumb.png"
  </code></pre>