Skip to content

Commit

Permalink
copy_to_bucket method to copy a file from a bucket to another bucket …
Browse files Browse the repository at this point in the history
…(say US -> EU for example)
  • Loading branch information
jakimowicz committed Jul 15, 2011
1 parent 1df25e2 commit 408d7f0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/aws/s3/object.rb
Expand Up @@ -189,6 +189,18 @@ def copy(key, copy_key, bucket = nil, options = {})
end
end

# Makes a copy of the object with <tt>key</tt> to <tt>copy_key</tt>, preserving the ACL of the existing object if the <tt>:copy_acl</tt> option is true (default false).
def copy_to_bucket(key, copy_key, source_bucket, destination_bucket, options = {})
source_bucket = bucket_name(source_bucket)
destination_bucket = bucket_name(destination_bucket)
source_key = path_with_bucket!(source_bucket, key)
default_options = {'x-amz-copy-source' => URI.escape(source_key)}
target_key = path!(copy_key)
returning put(destination_bucket, target_key, default_options.merge(options)) do
acl(copy_key, destination_bucket, acl(key, source_bucket)) if options[:copy_acl]
end
end

# Rename the object with key <tt>from</tt> to have key in <tt>to</tt>.
def rename(from, to, bucket = nil, options = {})
copy(from, to, bucket, options)
Expand Down

0 comments on commit 408d7f0

Please sign in to comment.