Method: Aws::S3::Object#copy_from

Defined in:
lib/aws-sdk-resources/services/s3/object.rb

#copy_from(source, options = {}) ⇒ Object

Copies another object to this object. Use ‘multipart_copy: true` for large objects. This is required for objects that exceed 5GB.

Examples:

Basic object copy


bucket = Aws::S3::Bucket.new('target-bucket')
object = bucket.object('target-key')

# source as String
object.copy_from('source-bucket/source-key')

# source as Hash
object.copy_from(bucket:'source-bucket', key:'source-key')

# source as Aws::S3::Object
object.copy_from(bucket.object('source-key'))

Managed copy of large objects


# uses multipart upload APIs to copy object
object.copy_from('src-bucket/src-key', multipart_copy: true)

Parameters:

  • source (S3::Object, S3::ObjectVersion, S3::ObjectSummary, String, Hash)

    Where to copy object data from. ‘source` must be one of the following:

    • Aws::S3::Object

    • Aws::S3::ObjectSummary

    • Aws::S3::ObjectVersion

    • Hash - with ‘:bucket` and `:key` and optional `:version_id`

    • String - formatted like ‘“source-bucket-name/uri-escaped-key”` or `“source-bucket-name/uri-escaped-key?versionId=version-id”`

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :multipart_copy (Boolean) — default: false

    When ‘true`, the object will be copied using the multipart APIs. This is necessary for objects larger than 5GB and can provide performance improvements on large objects. Amazon S3 does not accept multipart copies for objects smaller than 5MB.

  • :content_length (Integer)

    Only used when ‘:multipart_copy` is `true`. Passing this options avoids a HEAD request to query the source object size.

  • :copy_source_client (S3::Client)

    Only used when ‘:multipart_copy` is `true` and the source object is in a different region. You do not need to specify this option if you have provided `:content_length`.

  • :copy_source_region (String)

    Only used when ‘:multipart_copy` is `true` and the source object is in a different region. You do not need to specify this option if you have provided a `:source_client` or a `:content_length`.

See Also:



61
62
63
64
65
66
67
68
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 61

def copy_from(source, options = {})
  if Hash === source && source[:copy_source]
    # for backwards compatibility
    @client.copy_object(source.merge(bucket: bucket_name, key: key))
  else
    ObjectCopier.new(self, options).copy_from(source, options)
  end
end