Question

I try to copy a couple of files located on my container using the method

CF_container->copy_object_to('th/image_a.jpg',Object(CF_container),'th/image_a_copy.jpg')

But when I try to copy a file that exists I got this message

Specified object 'container_name/th/image_a.jpg' did not exist as source to copy from or 'container_name' did not exist as target to copy to.

What I doing wrong? This operation is impossible to do? This operation cannot allowed?

Thanks for your answer.

Was it helpful?

Solution

It looks like you're using the SDK from php-cloudfiles. The copy_object_to function can be found on github here.

That library has been deprecated in favor of php-opencloud. The documentation can be found here

The new function to use when copying an object is DataObject::Copy and can be found here.

The programming logic to make a copy of a Cloud Files object with the php-opencloud library would look something like the following:

// we must include this file
require_once "php-opencloud.php";

define('AUTHURL', RACKSPACE_US);

// create new Rackspace connection
$connection = new \OpenCloud\Rackspace(AUTHURL,
                array('username' => USERNAME, 'apiKey' => APIKEY));

// connect to ObjectStore
$object_store = $connection->ObjectStore();

// create a container named CONTAINER_NAME
$cont = $ostore->Container();
$cont->Create(array('name'=>CONTAINER_NAME));

// create an object in that container
$obj = $cont->DataObject();
$obj->Create(array('name' => 'test_obj', 'content_type' => 'text/plain'), __FILE__);

// copy it to another object
$target = $cont->DataObject();
$target->name = $obj->Name().'-COPY';
$obj->Copy($target);

If you are unable to upgrade to using the php-opencloud library, it looks like another user had a similar problem here and tracked it down to a double-encoded slash.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top