...begins in wonder


navigation
home
email
github
mastodon
twitter
about
code, poetry, philosophy, folly (Andrew Kuklewicz)

Amazon Web Services (AWS) S3 working, now back to the plan

12 Jan 2007

I've been spending the last few days working with the AWS::S3 library.

Works well - we are streaming large audio files over it, so we needed something better than the ruby s3 bindings amazon released (though they are very clear in their code that they do not handle big files well).

Only hitch was setting metadata when creating an AWS::S3::S3Object - couldn't get it to work.
Tried creating a 1 byte file to start, then updating with metadata, that was fine, but the initial create was erroring out, or the metadata would not take.

Luckily, there is a patch offered by 'Lars' which makes it all work for me now.

I posted this to the list, but here is some sample working code for setting metadata on create (once the patch is applied):

1) Using the store class method:

AWS::S3::S3Object.store(
'myfile-81805',
open('/data/production/amazon/myfolder/myfile-81805'),
'my-s3-bucket',
:content_type=>'audio/mpeg',
'x-amz-meta-my-file-name'=>'my.mp3')

2) Using the Bucket new_object method, and then store, you don't have to include the metadata prefix 'x-amz-meta-':

my_bucket = AWS::S3::Bucket.find('my-s3-bucket')
s3o = my_bucket.new_object
s3o.key = 'myfile-81805'
s3o.value = open('/data/production/amazon/myfolder/myfile-81805')
s3o.content_type = 'audio/mpeg'
s3o.metadata['my-file-name'] = 'my.mp3'
s3o.store

So with that working, back to ActiveMessaging, and getting changes fully tested and checked in.