Skip to content

Instantly share code, notes, and snippets.

@etudor
Created November 23, 2017 21:46
Show Gist options
  • Save etudor/e85689aa88b8436f2803e11ff8b99251 to your computer and use it in GitHub Desktop.
Save etudor/e85689aa88b8436f2803e11ff8b99251 to your computer and use it in GitHub Desktop.
upload a file to ovh openstack object storage via PHP
// install package: rackspace/php-opencloud
$client = new OpenCloud\OpenStack('https://auth.cloud.ovh.net/v2.0', [
'username' => self::OVH_OPENSTACK_USERNAME,
'password' => self::OVH_OPENSTACK_PASSWORD,
'tenantId' => self::OVH_OPENSTACK_PROJECT_ID,
]);
// 2. Obtain an Object Store service object from the client.
$objectStoreService = $client->objectStoreService('swift', 'DE1');
// 3. Get container.
$container = $objectStoreService->getContainer(self::OVH_OPENSTACK_CONTAINER_NAME);
// 5. Specify any metadata you want your objects to have
$metadata = array('test' => '1');
$metadataHeaders = DataObject::stockHeaders($metadata);
// 6. Merge the metadata with any additional HTTP headers you want to set
$allHttpHeaders = array('Cache-Control' => 'max-age=2592000, public') + $metadataHeaders;
// open file
$resource = fopen('test.jpg', 'r');
// upload file
$container->uploadObject('test123.jpg', $resource, $allHttpHeaders);
@romainlaisne
Copy link

romainlaisne commented Mar 24, 2020

WARNING : v2 is discarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment