szhorvath / flysystem-aws-s3-plus
用于Flysystem的AWS S3文件系统适配器,扩展了S3存储桶对象的版本控制
v1.0.1
2023-11-16 14:17 UTC
Requires
- php: ^8.1
- illuminate/conditionable: ^10.31
- illuminate/filesystem: ^10.31
- illuminate/support: *
- league/flysystem-aws-s3-v3: ^3.19.0
Requires (Dev)
- defstudio/pest-plugin-laravel-expectations: ^2.1
- laravel/pint: ^1.13
- orchestra/testbench: ^8.15
- pestphp/pest: ^2.24
- pestphp/pest-plugin-type-coverage: ^2.4
README
用于Flysystem的AWS S3文件系统适配器,扩展了S3存储桶对象的版本控制
文档和安装说明
磁盘配置
flysystem-aws-s3-plus
包需要您更改config/filesystems.php
文件中的磁盘驱动程序配置。对于每个已版本化的S3存储桶磁盘,将驱动程序从s3
更改为s3-plus
。
<?php return [ ... 'disks' => [ ... 's3' => [ 'driver' => 's3-plus', ... ], ], ...
使用方法
获取S3对象版本
Storage::disk('s3')->versions("path/to/file.text");
响应
Illuminate\Support\Collection { [ [ "id" => "9a18981b-fa18-4793-b406-4deb75744865", "hash" => "d93328ed2d2032d8bb6d8c1b49cfc807", "key" => "test/text.txt", "type" => "file", "latest" => true, "updatedAt" => Carbon\CarbonImmutable, "size" => 14, ], [ "id" => "b1baa201-6a3e-4d75-8d36-38895202d8ff", "hash" => "", "key" => "test/text.txt", "type" => "deleteMarker", "latest" => false, "updatedAt" => Carbon\CarbonImmutable, "size" => 0, ], [ "id" => "c22753cc-dfb2-4120-992c-ae81effef752", "hash" => "9310ca6aea85baa1adb30292d379b274", "key" => "test/text.txt", "type" => "file", "latest" => false, "updatedAt" => Carbon\CarbonImmutable, "size" => 12, ], ] }
为特定版本的对象生成临时URL
Storage::disk('s3')->temporaryUrl( path: 'path/to/file.txt', expiration: Carbon::now()->addMinutes(1), versionId: 'ca3dd4a6-9a92-4368-8ce2-a5df45c63f43' );
响应
http://s3/bucket/path/to/file.txt?versionId=ca3dd4a6-9a92-4368-8ce2-a5df45c63f43&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sail%2F20231114%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20231114T170430Z&X-Amz-SignedHeaders=host&X-Amz-Expires=60&X-Amz-Signature=f59d8e667cee7ac9ed5bc1fcfcd4cd02dd742fb9e4dd3f034186ec22dd699647
获取特定版本的文件内容
Storage::disk('s3')->get( path: 'path/to/file.txt', versionId: 'b51e44fe-d47e-43dd-be6e-d07a4dd823d4' );
软删除对象(s)或永久删除对象的特定版本(s)
如果启用了版本控制,您不能通过不指定版本ID的简单DELETE请求永久删除对象。相反,Amazon S3会在存储桶中插入删除标记,该标记成为具有新ID的对象的当前版本。要永久删除版本化对象,您必须提供versionId。
更多信息请参阅:从启用版本控制的存储桶中删除对象版本
//Multiple paths as arguments Storage::disk('s3')->delete('path/to/file1.txt', 'path/to/file2.txt', ...); // Multiple paths as array Storage::disk('s3')->delete(['path/to/file1.txt', 'path/to/file2.txt', ...]); // Delete specific version(s) permanently Storage::disk('s3')->delete([ 'f8ffee13-9a0f-4031-85e7-f92f253ec42e' => 'path/to/file1.txt', // versionId => path 'b51e44fe-d47e-43dd-be6e-d07a4dd823d4' => 'path/to/file2.txt', ... ]);
恢复以前版本
// Deleting the Delete marker Storage::disk('s3')->delete(['f8ffee13-9a0f-4031-85e7-f92f253ec42e' => 'path/to/file1.txt']); // Copy a previous version of the object into the same bucket. Storage::disk('s3')->restore('path/to/file1.txt', 'f8ffee13-9a0f-4031-85e7-f92f253ec42e');
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
欢迎贡献,并将完全归功于贡献者。
通过Github的拉取请求接受贡献。
拉取请求
-
记录任何行为变化 - 确保readme.md和其他相关文档保持最新。
-
考虑我们的发布周期 - 我们尽量遵循SemVer v2.0.0。随机破坏公共API不是可选项。
-
每个功能一个拉取请求 - 如果您想做更多的事情,请发送多个拉取请求。
安全
如果您发现任何安全相关的问题,请通过电子邮件z.sandor.horvath@gmail.com而不是使用问题跟踪器。
许可
许可。请参阅许可文件以获取更多信息。