PUT Object (Copy)
Description
This implementation of the PUT
operation creates a copy of an
object that is already stored in Amazon S3. A PUT
copy operation is the
same as performing a GET
and then a PUT
.
Adding the request header, x-amz-copy-source
, makes the PUT
operation copy the source object into the destination bucket.
When copying an object, you can preserve most of the metadata (default) or specify new
metadata. However, the ACL is not preserved and is set to private
for the
user making the request. To override the default ACL setting, use the x-amz-acl
header to specify a new ACL when generating a copy request.
For more information, see
All copy requests must be authenticated and cannot contain a message body. Additionally, you must have READ access to the source object and WRITE access to the destination bucket. For more information, see REST Authentication.
To only copy an object under certain conditions, such as whether the ETag
matches or whether the object was modified before or after a
specified date, use the request headers x-amz-copy-source-if-match
,
x-amz-copy-source-if-none-match
,
x-amz-copy-source-if-unmodified-since
, or
x-amz-copy-source-if-modified-since
.
![]() | Note |
---|---|
All headers prefixed with |
There are two opportunities for a copy request to return an error. One can occur when
Amazon S3 receives the copy request and the other can occur while Amazon S3 is copying the files.
If the error occurs before the copy
operation starts, you receive a
standard Amazon S3 error. If the error occurs during the copy
operation,
the error response is embedded in the 200 response. This means that a 200 response can
contain either a success or an error. Make sure to design your application to parse the
contents of the response and handle it appropriately.
If the copy is successful, you receive a response that contains the information about the copied object.
![]() | Note |
---|---|
If the request is an HTTP 1.1 request, the response is chunk encoded. Otherwise, it will not contain the content-length and you will need to read the entire body. |
Requests
Syntax
PUT /destinationObject
HTTP/1.1 Host:destinationBucket
.s3.amazonaws.com x-amz-copy-source: /source_bucket
/sourceObject
x-amz-metadata-directive:metadata_directive
x-amz-copy-source-if-match:etag
x-amz-copy-source-if-none-match:etag
x-amz-copy-source-if-unmodified-since:time_stamp
x-amz-copy-source-if-modified-since:time_stamp
<request metadata
> Authorization:signatureValue
Date:date
Request Parameters
This implementation of the operation does not use request parameters.
Request Headers
This implementation of the operation can use the following request headers in addition to the request headers common to all operations. For more information, see Common Request Headers.
Name | Description | Required |
---|---|---|
x-amz-acl
|
The canned ACL to apply to the object. For more information, go to REST Access Policy in the Amazon Simple Storage Service Developer Guide . Type: String Default: private Valid Values: private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control Constraints: None |
No |
x-amz-copy-source |
The name of the source bucket and key name of the source object, separated by a slash (/). Type: String Default: None Constraints: This string must be URL-encoded. Additionally, the source bucket must be valid and you must have READ access to the valid source object. |
Yes |
x-amz-metadata-directive |
Specifies whether the metadata is copied from the source object or replaced with metadata provided in the request. If copied, the metadata, except for the version ID, remains unchanged. Otherwise, all original metadata is replaced by the metadata you specify. Type: String Default: Valid values: Constraints: Values other than For information on supported metadata, see Common Request Headers |
No |
x-amz-copy-source-if-match |
Copies the object if its entity tag (ETag) matches the specified tag; otherwise, the request returns a 412 HTTP status code error (precondition failed). Type: String Default: None Constraints: This header can be used with
|
No |
x-amz-copy-source-if-none-match |
Copies the object if its entity tag (ETag) is different than the specified ETag; otherwise, the request returns a 412 HTTP status code error (failed condition). Type: String Default: None Constraints: This header can be used with
|
No |
x-amz-copy-source-if-unmodified-since |
Copies the object if it hasn't been modified since the specified time; otherwise, the request returns a 412 HTTP status code error (precondition failed). Type: String Default: None Constraints: This must be a valid HTTP date. For more
information, go to http://www.ietf.org/rfc/rfc2616.txt. This header
can be used with |
No |
x-amz-copy-source-if-modified-since |
Copies the object if it has been modified since the specified time; otherwise, the request returns a 412 HTTP status code error (failed condition). Type: String Default: None Constraints: This must be a valid HTTP date. This header can
be used with |
No |
Request Elements
This implementation of the operation does not use request elements.
Responses
Response Headers
This implementation of the operation can include the following response headers in addition to the response headers common to all responses. For more information, see Common Response Headers.
Name | Description |
---|---|
x-amz-copy-source-version-id
|
Version of the source object that was copied. Type: String |
x-amz-version-id
|
Version of the copied object in the destination bucket. Type: String |
Response Elements
Name | Description |
---|---|
CopyObjectResult
|
Container for all response elements. Type: Container Ancestor: None |
ETag
|
Returns the ETag of the new object. The ETag only reflects changes to the contents of an object, not its metadata. Type: String Ancestor: CopyObjectResult |
LastModified
|
Returns the date the object was last modified. Type: String Ancestor: CopyObjectResult |
Special Errors
This implementation of the operation does not return special errors. For general information about Amazon S3 errors and a list of error codes, see Error Responses.
Examples
Sample Request
This example copies my-image.jpg
into the bucket,
bucket
, with the key name my-second-image.jpg
.
PUT /my-second-image.jpg HTTP/1.1 Host: bucket.s3.amazonaws.com Date: Wed, 28 Oct 2009 22:32:00 GMT x-amz-copy-source: /bucket/my-image.jpg Authorization: AWS 02236Q3V0WHVSRW0EXG2:0RQf4/cRonhpaBX5sCYVf1bNRuU=
Sample Response
HTTP/1.1 200 OK x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran x-amz-request-id: 318BC8BC148832E5 x-amz-copy-source-version-id: 3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo x-amz-version-id: QUpfdndhfd8438MNFDN93jdnJFkdmqnh893 Date: Wed, 28 Oct 2009 22:32:00 GMT Connection: close Server: AmazonS3 <CopyObjectResult> <LastModified>2009-10-28T22:32:00</LastModified> <ETag>"9b2cf535f27731c974343645a3985328"</ETag> </CopyObjectResult>
x-amz-version-id
returns the version ID of the object in
the destination bucket and x-amz-copy-source-version-id
returns the version ID of the source object.
Sample Request Copying a Specified Version of an Object
The following request copies the key, my-image.jpg
, with
the specified version ID and copies it into the bucket, bucket
,and gives it the key, my-second-image.jpg
.
PUT /my-second-image.jpg HTTP/1.1
Host: bucket.s3.amazonaws.com
Date: Wed, 28 Oct 2009 22:32:00 GMT
x-amz-copy-source: /bucket/my-image.jpg?versionId=3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo
Authorization: AWS 02236Q3V0WHVSRW0EXG2:0RQf4/cRonhpaBX5sCYVf1bNRuU=
Success Response Copying a Versioned Object into a Version Enabled Bucket
The following response shows that an object was copied into a target bucket where Versioning is enabled.
HTTP/1.1 200 OK
x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran
x-amz-request-id: 318BC8BC148832E5
x-amz-version-id: QUpfdndhfd8438MNFDN93jdnJFkdmqnh893
x-amz-copy-source-version-id: 09df8234529fjs0dfi0w52935029wefdj
Date: Wed, 28 Oct 2009 22:32:00 GMT
Connection: close
Server: AmazonS3
<?xml version="1.0" encoding="UTF-8"?>
<CopyObjectResult>
<LastModified>2009-10-28T22:32:00</LastModified>
<ETag>"9b2cf535f27731c974343645a3985328"</ETag>
</CopyObjectResult>
Success Response Copying a Versioned Object into a Version Suspended Bucket
The following response shows that an object was copied into a target bucket where
Versioning is suspended. Note that the parameter,<VersionId>
, does not appear.
HTTP/1.1 200 OK x-amz-id-2: eftixk72aD6Ap51TnqcoF8eFidJG9Z/2mkiDFu8yU9AS1ed4OpIszj7UDNEHGran x-amz-request-id: 318BC8BC148832E5 x-amz-copy-source-version-id: 3/L4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUMLUo Date: Wed, 28 Oct 2009 22:32:00 GMT Connection: close Server: AmazonS3 <?xml version="1.0" encoding="UTF-8"?> <CopyObjectResult> <LastModified>2009-10-28T22:32:00</LastModified> <ETag>"9b2cf535f27731c974343645a3985328"</ETag> </CopyObjectResult>