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

56 lines
2.7 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>:
# * :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>:
# * :etag<~String> - etag of new object
# * :last_modified<~Time> - date object was last modified
#
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 = {})
headers = { 'x-amz-copy-source' => "/#{source_bucket_name}/#{source_object_name}" }
if options[:x_amz_metadata_directive]
headers['x-amz-metadata-directive'] = options[:x_amz_metadata_directive]
end
if options[:x_amz_copy_source_if_match]
headers['x-amz-copy-source-if-match'] = options[:x_amz_copy_source_if_match]
end
if options[:x_amz_copy_source_if_modified_since]
headers['x-amz-copy-source-if-modified-since'] = options[:x_amz_copy_source_if_modified_since].utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
end
if options[:x_amz_copy_source_if_none_match]
headers['x-amz-copy-source-if-none-match'] = options[:x_amz_copy_source_if_none_match]
end
if options[:x_amz_copy_source_if_unmodified_since]
headers['x-amz-copy-source-if-unmodified-since'] = options[:x_amz_copy_source_if_unmodified_since].utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
end
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