Sending HEAD requests using Amazon's S3 Ruby lib

After some usage of Amazon's S3 storage service from Ruby, I'm quite happy with the result obtained. Amazon's S3 Ruby library makes it quite easy to start playing with S3 from Ruby. I'm posting this essentially to share a minimal addition ( adapted S3.rb version, or patch for S3.rb available on 2006-05-21) to this (REST) library: sending head requests which wasn't possible. The library also uses openssl in place of hmac-sha1 (following Daniel Amenlang's indications). HEAD requests allow you to get information about an object stored on S3, without having to actually download it. I was actually interested in getting the size of the object without downloading it. This is now possible:
#first connect with your credentials:

#and then send the head request
r= @s3_conn.head("mybucketl", "my_key")
Another little trick: you can point people to a S3 URL to let them download a stored object, even if they don't have a S3 account. By default, the name proposed by the browser under which to save the file is the value of the key identifying the file on S3. You can define the filename to propose when you upload the file to S3 by setting the "Content-Disposition" header of the request to
When sending to s3 a file uploaded to your Rails app, you can do this ( file = params["name_of_your_file_unput"] )
@s3_conn.put(bucket_name, key_value ,, 
{ 'Content-Type' => file.content_type, "Content-Length" => file.size.to_s,
   "Content-Disposition"=> "attachment;filename=\"#{file.original_filename}\"" })
When you direct users to that file thanks to this ruby code:
     generator =, AWS_SECRET_ACCESS_KEY)
     generator.expires_in = 60
     url = generator.get(bucket_name, "my_key")
which generates a URL of this form ( wrapped for readability):\\
the browser will propose to save the file under the name it had when it was uploaded.