nimbusoft / flysystem-openstack-swift
OpenStack Swift 的 Flysystem 适配器
1.5.0
2023-02-27 08:16 UTC
Requires
- php: ^7.4 | ^8.0
- guzzlehttp/psr7: ^2.0
- league/flysystem: ^2.0 | ^3.0
- php-opencloud/openstack: ^3.2
Requires (Dev)
- mockery/mockery: >= 1.3.1
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.20
README
OpenStack Swift 的 Flysystem 适配器。
安装
composer require nimbusoft/flysystem-openstack-swift
使用方法
$openstack = new OpenStack\OpenStack([ 'authUrl' => '{authUrl}', 'region' => '{region}', 'user' => [ 'id' => '{userId}', 'password' => '{password}' ], 'scope' => ['project' => ['id' => '{projectId}']] ]); $container = $openstack->objectStoreV1() ->getContainer('{containerName}'); $adapter = new Nimbusoft\Flysystem\OpenStack\SwiftAdapter($container); $flysystem = new League\Flysystem\Filesystem($adapter);
配置
Swift 适配器有以下配置选项
上传大对象
更多详细信息请查看 OpenStack 文档
swiftLargeObjectThreshold
:文件大小(字节)达到时切换到大对象上传流程。默认为 300 MiB。常规对象的最大允许大小为 5 GiB。swiftSegmentSize
:大文件拆分成的单个段或块的大小。默认为 100 MiB。应小于 5 GiB。swiftSegmentContainer
:存储大对象段的 Swift 容器名称。默认与存储常规文件的容器相同。
内容类型
contentType
:设置请求的 Content-Type 标头。detectContentType
:如果设置为 true,Object Storage 将根据文件扩展名猜测内容类型,并忽略 Content-Type 标头中发送的值(如果存在)。
文件过期
deleteAfter
:指定对象被移除后的秒数。内部,Object Storage 系统将此值存储在 X-Delete-At 元数据项中。deleteAt
:对象将被移除的确切日期,格式为 UNIX Epoch 时间戳。
示例
这些选项可以在 Filesystem
创建时设置
$flysystem = new League\Flysystem\Filesystem($adapter, new \League\Flysystem\Config([ 'swiftLargeObjectThreshold' => 104857600, // 100 MiB 'swiftSegmentSize' => 52428800, // 50 MiB 'swiftSegmentContainer' => 'mySegmentContainer', ]));
或按文件设置
$flysystem->write($path, $contents, new \League\Flysystem\Config([ 'swiftLargeObjectThreshold' => 52428800, // 50 MiB 'contentType' => 'text/plain', 'deleteAfter' => 3600, // 1 hour ])