Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

copy_to_bucket method to copy a file from a bucket to another bucket …

…(say US -> EU for example)
  • Loading branch information...
commit 408d7f0095a07666a783814b7bb240a56072816e 1 parent 1df25e2
Fabien Jakimowicz authored
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/aws/s3/object.rb
12 lib/aws/s3/object.rb
View
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.