A Flysystem v3 adapter for OpenStack Swift, using
php-opencloud/openstack.
If you're looking for a Flysystem v1 adapter, see
chrisnharvey/flysystem-openstack-swift.
$ composer require webalternatif/flysystem-openstack-swiftuse League\Flysystem\Filesystem;
use OpenStack\OpenStack;
use Webf\Flysystem\OpenStackSwift\OpenStackSwiftAdapter;
$openstack = new OpenStack([
'authUrl' => '{authUrl}',
'region' => '{region}',
'user' => [
'id' => '{userId}',
'password' => '{password}',
],
'scope' => ['project' => ['id' => '{projectId}']],
]);
$adapter = new OpenStackSwiftAdapter($openstack, '{containerName}');
$flysystem = new Filesystem($adapter);To use the createLargeObject method of the underlying OpenStack library to
upload large objects (which is mandatory for files over 5 GB), you must use
the writeStream method and define the segment_size config option.
The segment_container option is also available if you want to upload segments
in another container.
use Webf\Flysystem\OpenStackSwift\Config;
$flysystem->writeStream($path, $content, ([
Config::OPTION_SEGMENT_SIZE => 52428800, // 50 MiB
Config::OPTION_SEGMENT_CONTAINER => 'test_segments',
]);This adapter supports generating temporary URLs as described in Flysystem's documentation.
To do so, you must :
- set a secret key at the account or container level of your OpenStack Swift instance (see details in the OpenStack documentation),
- provide this secret key as third argument (
$tempUrlKey) when creating the adapter.
When calling Filesystem::temporaryUrl(), you can pass the following options as
third argument ($config):
| Option key | Description | Type | Default value |
|---|---|---|---|
digest |
The digest algorithm to use for the HMAC cryptographic signature (given as first parameter of hash_hmac). | string |
'sha256' |
file_name |
A string to override the default file name (which is based on the object name) when the file is downloaded. | string |
null |
prefix |
If true, a prefix-based temporary URL will be generated. |
bool |
false |
Those option keys are available as public constants in the
Webf\Flysystem\OpenStackSwift\Config class.
More information about those options can be found in the OpenStack documentation.
use League\Flysystem\Filesystem;
use Webf\Flysystem\OpenStackSwift\OpenStackSwiftAdapter;
// ... (see above)
$adapter = new OpenStackSwiftAdapter($openstack, '{containerName}', '{tempUrlKey}');
$flysystem = new Filesystem($adapter);
$flysystem->temporaryUrl($path, new DateTime('+1 hour'), [
// options...
]);This library uses the FilesystemAdapterTestCase provided by
league/flysystem-adapter-test-utilities, so it performs integration tests
that need a real OpenStack Swift container.
To run tests, duplicate the phpunit.xml.dist file into phpunit.xml and fill
all the environment variables, then run:
$ composer testThis will run Psalm and PHPUnit, but you can run them individually like this:
$ composer psalm
$ composer phpunit