aws / aws-sdk-ruby

The official AWS SDK for Ruby.
https://aws.amazon.com/sdk-for-ruby/
Apache License 2.0
3.57k stars 1.22k forks source link

AWS::S3::ObjectCollection - create method return an AWS::S3::ObjectVersion instead of an AWS::S3::S3Object #368

Closed mtparet closed 11 years ago

mtparet commented 11 years ago

Calling the instance method create on an AWS::S3::ObjectCollection is not consistency and return an AWS::S3::ObjectVersion (if the bucket has versioning activated) instead of an AWS::S3::S3Object.

Also this doesn't match the documentation: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/ObjectCollection.html#create-instance_method

Returns:
(S3Object)

The side-effect of this problem is that we can't use others usual S3 operations (like copy_to) with this object.

We should receive an S3Object and be able to retrieve the S3::ObjectVersion from this one to avoid to deal with a method returning different kind of objects.

trevorrowe commented 11 years ago

The documented return type is incorrect. The current behavior is intentional. I will update the docs to indicate that it returns a ObjectVersion when versioning is enabled on the bucket.

That said, it is very easy to get the object from an object version:

$ aws-rb
AWS> obj_version = AWS.s3.buckets['my-versioned-bucket'].objects['key'].write('data')
<AWS::S3::ObjectVersion:my-versioned-bucket:key:9MHtaVle8bWn1BtdFruEtu0IDoqA5fjy>
AWS> obj_version.object
=> <AWS::S3::S3Object:my-versioned-bucket/foo>
mtparet commented 11 years ago

Thanks a lot to have updated the documentation. However I still think this behavior add not necessary complexity. (dealing with two kinds of object returned from a same method/parameters)