示例程序【Samples/*.php】 的Common类,用于获取OssClient实例和其他公用方法
示例#1
0
 public function testBucket()
 {
     $websiteConfig = new WebsiteConfig("index.html", "error.html");
     try {
         $this->ossClient->putBucketWebsite($this->bucket, $websiteConfig);
     } catch (OssException $e) {
         var_dump($e->getMessage());
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $websiteConfig2 = $this->ossClient->getBucketWebsite($this->bucket);
         $this->assertEquals($websiteConfig->serializeToXml(), $websiteConfig2->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $this->ossClient->deleteBucketWebsite($this->bucket);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $websiteConfig3 = $this->ossClient->getBucketLogging($this->bucket);
         $this->assertNotEquals($websiteConfig->serializeToXml(), $websiteConfig3->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
 }
 public function setUp()
 {
     $this->client = Common::getOssClient();
     $this->bucketName = 'php-sdk-test-rtmp-bucket-name-' . strval(rand(0, 10000));
     $this->client->createBucket($this->bucketName);
     Common::waitMetaSync();
 }
 public function setUp()
 {
     $this->bucket = Common::getBucketName() . rand(100000, 999999);
     $this->ossClient = Common::getOssClient();
     $this->ossClient->createBucket($this->bucket);
     Common::waitMetaSync();
 }
示例#4
0
 public function testBucket()
 {
     $refererConfig = new RefererConfig();
     $refererConfig->addReferer('http://www.aliyun.com');
     try {
         $this->ossClient->putBucketReferer($this->bucket, $refererConfig);
     } catch (OssException $e) {
         var_dump($e->getMessage());
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $refererConfig2 = $this->ossClient->getBucketReferer($this->bucket);
         $this->assertEquals($refererConfig->serializeToXml(), $refererConfig2->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $nullRefererConfig = new RefererConfig();
         $nullRefererConfig->setAllowEmptyReferer(false);
         $this->ossClient->putBucketReferer($this->bucket, $nullRefererConfig);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $refererConfig3 = $this->ossClient->getBucketLogging($this->bucket);
         $this->assertNotEquals($refererConfig->serializeToXml(), $refererConfig3->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
 }
示例#5
0
 public function testBucket()
 {
     $loggingConfig = new LoggingConfig($this->bucket, 'prefix');
     try {
         $this->ossClient->putBucketLogging($this->bucket, $this->bucket, 'prefix');
     } catch (OssException $e) {
         var_dump($e->getMessage());
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $loggingConfig2 = $this->ossClient->getBucketLogging($this->bucket);
         $this->assertEquals($loggingConfig->serializeToXml(), $loggingConfig2->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $this->ossClient->deleteBucketLogging($this->bucket);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $loggingConfig3 = $this->ossClient->getBucketLogging($this->bucket);
         $this->assertNotEquals($loggingConfig->serializeToXml(), $loggingConfig3->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
 }
 public function setUp()
 {
     $this->client = Common::getOssClient();
     $this->bucketName = 'php-sdk-test-bucket-image-' . strval(rand(0, 10000));
     $this->client->createBucket($this->bucketName);
     Common::waitMetaSync();
     $this->local_file = "example.jpg";
     $this->object = "oss-example.jpg";
     $this->download_file = "image.jpg";
     $this->client->uploadFile($this->bucketName, $this->object, $this->local_file);
 }
 public function testBucket()
 {
     $this->ossClient->createBucket($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
     $bucketListInfo = $this->ossClient->listBuckets();
     $this->assertNotNull($bucketListInfo);
     $bucketList = $bucketListInfo->getBucketList();
     $this->assertTrue(is_array($bucketList));
     $this->assertGreaterThan(0, count($bucketList));
     $this->ossClient->putBucketAcl($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
     Common::waitMetaSync();
     $this->assertEquals($this->ossClient->getBucketAcl($this->bucket), OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
     $this->assertTrue($this->ossClient->doesBucketExist($this->bucket));
     $this->assertFalse($this->ossClient->doesBucketExist($this->bucket . '-notexist'));
 }
 public function testGetSet()
 {
     $client = Common::getOssClient();
     $bucket = Common::getBucketName();
     $object = 'test/object-acl';
     $client->deleteObject($bucket, $object);
     $client->putObject($bucket, $object, "hello world");
     $acl = $client->getObjectAcl($bucket, $object);
     $this->assertEquals('default', $acl);
     $client->putObjectAcl($bucket, $object, 'public-read');
     $acl = $client->getObjectAcl($bucket, $object);
     $this->assertEquals('public-read', $acl);
     $content = $client->getObject($bucket, $object);
     $this->assertEquals('hello world', $content);
 }
示例#9
0
 public function testBucket()
 {
     $this->ossClient->createBucket($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
     $bucketListInfo = $this->ossClient->listBuckets();
     $this->assertNotNull($bucketListInfo);
     $bucketList = $bucketListInfo->getBucketList();
     $this->assertTrue(is_array($bucketList));
     $this->assertGreaterThan(0, count($bucketList));
     $this->ossClient->putBucketAcl($this->bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
     Common::waitMetaSync();
     $this->assertEquals($this->ossClient->getBucketAcl($this->bucket), OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
     $this->assertTrue($this->ossClient->doesBucketExist($this->bucket));
     $this->assertFalse($this->ossClient->doesBucketExist($this->bucket . '-notexist'));
     try {
         $this->ossClient->deleteBucket($this->bucket);
     } catch (OssException $e) {
         $this->assertEquals("BucketNotEmpty", $e->getErrorCode());
         $this->assertEquals("409", $e->getHTTPStatus());
     }
 }
示例#10
0
 public function testByUser()
 {
     $client = Common::getOssClient();
     $bucket = Common::getBucketName();
     $object = "test/x.txt";
     $client->putObject($bucket, $object, "hello world", array('Content-Type' => 'text/html'));
     $type = $this->getContentType($bucket, $object);
     $this->assertEquals('text/html', $type);
     $file = '/tmp/x.html';
     $object = 'test/x';
     $this->runCmd('touch ' . $file);
     $client->uploadFile($bucket, $object, $file, array('Content-Type' => 'application/json'));
     $type = $this->getContentType($bucket, $object);
     $this->assertEquals('application/json', $type);
     $file = '/tmp/x.json';
     $object = 'test/y';
     $this->runCmd('dd if=/dev/random of=' . $file . ' bs=1024 count=100');
     $client->multiuploadFile($bucket, $object, $file, array('partSize' => 100, 'Content-Type' => 'audio/mpeg'));
     $type = $this->getContentType($bucket, $object);
     $this->assertEquals('audio/mpeg', $type);
 }
示例#11
0
 public function testBucket()
 {
     $lifecycleConfig = new LifecycleConfig();
     $actions = array();
     $actions[] = new LifecycleAction("Expiration", "Days", 3);
     $lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
     $lifecycleConfig->addRule($lifecycleRule);
     $actions = array();
     $actions[] = new LifecycleAction("Expiration", "Date", '2022-10-12T00:00:00.000Z');
     $lifecycleRule = new LifecycleRule("delete temporary files", "temporary/", "Enabled", $actions);
     $lifecycleConfig->addRule($lifecycleRule);
     try {
         $this->ossClient->putBucketLifecycle($this->bucket, $lifecycleConfig);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $lifecycleConfig2 = $this->ossClient->getBucketLifecycle($this->bucket);
         $this->assertEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig2->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $this->ossClient->deleteBucketLifecycle($this->bucket);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $lifecycleConfig3 = $this->ossClient->getBucketLifecycle($this->bucket);
         $this->assertNotEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig3->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
 }
示例#12
0
 public function setUp()
 {
     $this->client = Common::getOssClient();
     $this->bucketName = 'php-sdk-test-bucket-' . strval(rand(0, 10));
     $this->client->createBucket($this->bucketName);
 }
 public function setUp()
 {
     $this->bucket = Common::getBucketName();
     $this->ossClient = Common::getOssClient();
     $this->ossClient->createBucket($this->bucket);
 }
示例#14
-1
 public function testBucket()
 {
     $corsConfig = new CorsConfig();
     $rule = new CorsRule();
     $rule->addAllowedHeader("x-oss-test");
     $rule->addAllowedHeader("x-oss-test2");
     $rule->addAllowedHeader("x-oss-test2");
     $rule->addAllowedHeader("x-oss-test3");
     $rule->addAllowedOrigin("http://www.b.com");
     $rule->addAllowedOrigin("http://www.a.com");
     $rule->addAllowedOrigin("http://www.a.com");
     $rule->addAllowedMethod("GET");
     $rule->addAllowedMethod("PUT");
     $rule->addAllowedMethod("POST");
     $rule->addExposeHeader("x-oss-test1");
     $rule->addExposeHeader("x-oss-test1");
     $rule->addExposeHeader("x-oss-test2");
     $rule->setMaxAgeSeconds(10);
     $corsConfig->addRule($rule);
     $rule = new CorsRule();
     $rule->addAllowedHeader("x-oss-test");
     $rule->addAllowedMethod("GET");
     $rule->addAllowedOrigin("http://www.b.com");
     $rule->addExposeHeader("x-oss-test1");
     $rule->setMaxAgeSeconds(110);
     $corsConfig->addRule($rule);
     try {
         $this->ossClient->putBucketCors($this->bucket, $corsConfig);
     } catch (OssException $e) {
         $this->assertFalse(True);
     }
     try {
         Common::waitMetaSync();
         $object = "cors/test.txt";
         $this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
         $headers = $this->ossClient->optionsObject($this->bucket, $object, "http://www.a.com", "GET", "", null);
         $this->assertNotEmpty($headers);
     } catch (OssException $e) {
         var_dump($e->getMessage());
     }
     try {
         Common::waitMetaSync();
         $corsConfig2 = $this->ossClient->getBucketCors($this->bucket);
         $this->assertNotNull($corsConfig2);
         $this->assertEquals($corsConfig->serializeToXml(), $corsConfig2->serializeToXml());
     } catch (OssException $e) {
         $this->assertFalse(True);
     }
     try {
         Common::waitMetaSync();
         $this->ossClient->deleteBucketCors($this->bucket);
     } catch (OssException $e) {
         $this->assertFalse(True);
     }
     try {
         Common::waitMetaSync();
         $corsConfig3 = $this->ossClient->getBucketCors($this->bucket);
         $this->assertNotNull($corsConfig3);
         $this->assertNotEquals($corsConfig->serializeToXml(), $corsConfig3->serializeToXml());
     } catch (OssException $e) {
         $this->assertFalse(True);
     }
 }