Sha256: 472b9f0a8db351a3e814b827b77f5a5f7a971981c8534ad5a017fdf2937863b9
Contents?: true
Size: 1.71 KB
Versions: 4
Compression:
Stored size: 1.71 KB
Contents
= dm-s3 Very often we want to store a file in s3 and keep a record of it in our database. == Setting If you have a model class that will have s3 objects living in different buckets do property :s3_key, String property :s3_bucket, String has_s3_file and define a method to save your resource and your s3 object def self.create!(key, bucket, file, options) object = self.new :s3_key => key, :s3_bucket => bucket object.save if object.store_with(file, options) end If all the s3 objects will live in the same bucket then do property :s3_key, String has_s3_file_at 'my-bucket-name' The save method will reflect the difference def self.create!(key, file, options) object = self.new :s3_key => key object.save if object.store_with(file, options) end You can directly access the bucket object associated with this model too MyModel.bucket == Getting To retrieve data from s3 simply pull the datamapper object, e.g. object = MyModel.first Doing object.s3 Will give you the s3 object. So you can do things like object.s3.value object.s3.url object.s3.about etc. For convenience, the methods 'value', 'metadata', 'about' and 'url' get bound to the datamapper object directly so the following is valid object.value object.metadata object.about object.url Make sure these don't conflict with your properties. == Gotchas * The gem assumes that you will call AWS::S3::Base.establish_connection! with the appropriate credentials some time before you create or access your s3 enabled models * The gem won't create buckets for you. Make sure the buckets exist before attempting to use them. == Copyright Copyright (c) 2009 Roberto Thais. See LICENSE for details.
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
rpbertp13-dm-s3-0.1.2 | README.rdoc |
rpbertp13-dm-s3-0.1.4 | README.rdoc |
rpbertp13-dm-s3-0.1.5 | README.rdoc |
dm-s3-0.1.5 | README.rdoc |