Copy Object

Suppose you upload a file with the wrong object name or content type, or you needed to move some objects to another container. Without a server-side copy feature, you would need to repeat uploading the same content and then delete the existing object. With server-side object copy, you can save the step of re-uploading the content and thus also save the associated bandwidth charges, if any were to apply.

There are two ways to copy an existing object to another object in OpenStack Object Storage. One way is to do a PUT to the new object (the target) location, but add the “X-Copy-From” header to designate the source of the data. The header value should be the container and object name of the source object in the form of “/container/object”. The container and object name must be UTF-8 encoded and then URL-encoded. Also, the X-Copy-From PUT requests require a Content-Length header, even if it is zero (0).

 

Example 2.66. Object Copy Method 1

PUT /<api version>/<account>/<destcontainer>/<destobject> HTTP/1.1
Host: <storage URL>
X-Auth-Token: <some-auth-token>
X-Copy-From: /<sourcecontainer>/<sourceobject>
Content-Length: 0                    

The second way to do an object copy is similar. Do a COPY to the existing object, and include the “Destination” header to specify the target of the copy. The header value is the container and new object name in the form of “/container/object”.

 

Example 2.67. Object Copy Method 2

COPY /<api version>/&lt;account>/<sourcecontainer>/<sourceobject> HTTP/1.1
Host: <storage URL>
X-Auth-Token: <some-auth-token>
Destination: /<destcontainer>/<destobject>

With both of these methods, the destination container must exist before attempting the copy.

If the source object is a manifest object, i.e., an object with X-Object-Manifest or X-Static-Large-Object:true metadata, the copy operation concatenates the segment objects when making the content for the destination object. You cannot copy an object larger than 5GB (by default). Refer to Large Object Creation for more information about large objects.

However, for a Static Large Object manifest, it is possible to copy the manifest so that the destination becomes a manifest object. Use the ?multipart-manifest=get query string to indicate that you want a copy of the manifest object. The new object will contain the same manifest as the original. The segment objects are not copied. Instead, both the original and new manifest objects share the same set of segment objects.

If you wanted to move the object rather than copy it, you need to send a DELETE request to the old object. A move is simply a COPY + DELETE. All metadata is preserved during the object copy. Note that you can set metadata on the request to copy the object (either the PUT or the COPY) and the metadata will overwrite any conflicting keys on the target (new) object. One interesting use case is to copy an object to itself and set the content type to a new value. This is the only way to change the content type of an existing object.

Log a bug against this page


loading table of contents...