1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/requests/s3/copy_object.rb

41 lines
1.8 KiB
Ruby
Raw Normal View History

module Fog
module AWS
class S3
# Copy an object from one S3 bucket to another
2009-07-20 22:47:48 -04:00
#
# ==== Parameters
# * source_bucket_name<~String> - Name of source bucket
# * source_object_name<~String> - Name of source object
# * destination_bucket_name<~String> - Name of bucket to create copy in
# * destination_object_name<~String> - Name for new copy of object
2009-07-29 00:23:28 -04:00
# * options<~Hash>:
2009-07-29 22:50:51 -04:00
# * 'x-amz-metadata-directive'<~String> - Specifies whether to copy metadata from source or replace with data in request. Must be in ['COPY', 'REPLACE']
# * 'x-amz-copy_source-if-match'<~String> - Copies object if its etag matches this value
# * 'x-amz-copy_source-if-modified_since'<~Time> - Copies object it it has been modified since this time
# * 'x-amz-copy_source-if-none-match'<~String> - Copies object if its etag does not match this value
# * 'x-amz-copy_source-if-unmodified-since'<~Time> - Copies object it it has not been modified since this time
2009-07-20 22:47:48 -04:00
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
2009-07-29 22:50:51 -04:00
# * 'ETag'<~String> - etag of new object
# * 'LastModified'<~Time> - date object was last modified
2009-07-20 22:47:48 -04:00
#
2009-07-29 00:23:28 -04:00
# TODO: allow specifying new metadata (support all/some of put_object?)
def copy_object(source_bucket_name, source_object_name, destination_bucket_name, destination_object_name, options = {})
2009-07-29 22:50:51 -04:00
headers = { 'x-amz-copy-source' => "/#{source_bucket_name}/#{source_object_name}" }.merge!(options)
request({
:expects => 200,
2009-07-29 00:23:28 -04:00
:headers => headers,
:host => "#{destination_bucket_name}.#{@host}",
:method => 'PUT',
:parser => Fog::Parsers::AWS::S3::CopyObject.new,
:path => destination_object_name
})
end
end
end
end