ลองเล่น Ceph S3 โดยใช้ AWS PHP SDK v2 http://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html
ไม่มีอะไร มาแชร์ข้อสังเกตุที่เจอดังนี้
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
<?php require 'vendor/autoload.php'; use Aws\S3\S3Client; /* * ต้องทำ wildcard ชี้ *.s3.example.com ไปยัง Ceph RadosGW node * เพราะว่า bucket student.image จะชี้ไปที่ student.image.s3.example.com */ $s3 = S3Client::factory([ 'key' => 'photo.student key', 'secret' => 'photo.student secret', 'endpoint' => 'http://s3.example.com' ]); /* สร้าง bucket student.image */ $s3->createBucket(['Bucket' => 'student.image']); /* * ทดสอบตั้งค่า ACL ให้ Bucket โดยที่การ putBucketAcl() จะเป็นการทับ ACL เดิมทั้งหมด * ดังนั้น จึงต้องใส่ค่า Owner และ Grant Owner ด้วย */ $result = $s3->putBucketAcl([ 'Owner' => [ 'DisplayName' => 'Students Photo Bucket', 'ID' => 'photo.student', ], 'Grants' => [ [ 'Grantee' => [ 'Type' => 'CanonicalUser', 'ID' => 'photo.student', ], 'Permission' => 'FULL_CONTROL', ], /* grant read uid=photo.student.ro ให้ อ่านรายชื่อ object ใน bucket student.image ได้ */ [ 'Grantee' => [ 'Type' => 'CanonicalUser', 'ID' => 'photo.student.ro', ], 'Permission' => 'READ', ], ], 'Bucket' => 'student.image', ]); /* dump ACL bucket student.image */ var_dump($s3->getBucketAcl([ 'Bucket' => 'student.image', ])); /* ทำการ upload test.jpg พร้อมกำหนด ACL */ $s3->putObject([ 'Bucket' => 'student.image', 'Key' => 'test', 'Body' => fopen("test.jpg", 'r'), 'GrantRead' => 'id=photo.student.ro', 'GrantFullControl' => 'id=photo.student', ]); /* ทดสอบด้วย Read only account */ $s3ro = S3Client::factory([ 'key' => 'photo.student.ro key', 'secret' => 'photo.student.ro secret', 'endpoint' => 'http://s3.example.com' ]); /* ทำการสร้าง url สำหรับเรียกดู test.jpg โดย url จะมีอายุ 1 นาที */ $command = $s3ro->getCommand('GetObject', [ 'Bucket' => 'student.image', 'Key' => 'test', ]); $signedUrl = $command->createPresignedUrl('+1 minutes'); echo "{$signedUrl}\n"; |