Created
November 23, 2017 21:46
-
-
Save etudor/e85689aa88b8436f2803e11ff8b99251 to your computer and use it in GitHub Desktop.
upload a file to ovh openstack object storage via PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WARNING : v2 is discarded.