diff --git a/README.md b/README.md index f15482a..eac7252 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ php ./examples/galaxy-fds.php (注意: 需要在样例中设置正确的App Key和Secret) +##### Release Notes: +* 20170309 - v1.0.0 + * Fix metadata not set in completeMultipartUpload + * Add setEndpoint in FDSClientConfiguration FDS PHP SDK User Guide ======================== diff --git a/src/FDS/FDSClientConfiguration.php b/src/FDS/FDSClientConfiguration.php index 531564d..71996d7 100644 --- a/src/FDS/FDSClientConfiguration.php +++ b/src/FDS/FDSClientConfiguration.php @@ -17,7 +17,7 @@ class FDSClientConfiguration { const URI_CDN_SUFFIX = "fds.api.mi-img.com"; const DEFAULT_RETRY_NUM = 3; const DEFAULT_CONNECTION_TIMEOUT_SECS = 30; - const DEFAULT_MAX_BATCH_DELETE_SIZE = 100; + const DEFAULT_MAX_BATCH_DELETE_SIZE = 1000; private $region_name; private $enable_https; @@ -29,6 +29,7 @@ class FDSClientConfiguration { private $retry; private $connection_timeout_secs; private $batch_delete_size; + private $endpoint; private $enable_unit_test_mode; private $base_uri_for_unit_test; @@ -41,6 +42,7 @@ public function __construct() { $this->enable_md5_calculate = false; $this->enable_debug = false; $this->enable_metrics = false; + $this->endpoint = ""; $this->enable_unit_test_mode = false; $this->base_uri_for_unit_test = ""; @@ -100,6 +102,14 @@ public function setBaseUriforunittest($base_uri_for_unit_test) { $this->base_uri_for_unit_test = $base_uri_for_unit_test; } + public function setEndpoint($endpoint) { + $this->endpoint = $endpoint; + } + + public function getEndpoint($endpoint) { + return $this->endpoint; + } + public function getBaseUri() { return $this->buildBaseUri(false); } @@ -122,7 +132,10 @@ public function buildBaseUri($enableCdn) { } $uri = $this->enable_https ? self::URI_HTTPS_PREFIX : self::URI_HTTP_PREFIX; - if ($enableCdn) { + + if (!empty($this->endpoint)) { + $uri .= $this->endpoint; + } else if ($enableCdn) { $uri .= self::URI_CDN . '.' . $this->region_name . '.' . self::URI_CDN_SUFFIX; } else { $uri .= $this->region_name . '.' . self::URI_SUFFIX; @@ -175,4 +188,4 @@ public function setBatchDeleteSize($size) { $this->batch_delete_size = min($size, SELF::DEFAULT_MAX_BATCH_DELETE_SIZE); $this->batch_delete_size = max(1, $this->batch_delete_size); } -} +} \ No newline at end of file diff --git a/src/FDS/GalaxyFDS.php b/src/FDS/GalaxyFDS.php index c5a7ac4..9548d3b 100644 --- a/src/FDS/GalaxyFDS.php +++ b/src/FDS/GalaxyFDS.php @@ -225,7 +225,7 @@ public function deleteObject($bucket_name, $object_name); * * @param string $bucket_name The name of the bucket * @param $object_name_list array of names to delete, count($object_name_list) - * should less than 100 + * should less than 1k * @return array of failure reason: * (..., * ( @@ -362,4 +362,4 @@ public function generatePresignedUri($bucket_name, $object_name, $expiration, * @throws GalaxyFDSClientException */ public function generateDownloadObjectUri($bucket_name, $object_name); -} +} \ No newline at end of file diff --git a/src/FDS/GalaxyFDSClient.php b/src/FDS/GalaxyFDSClient.php index 80de7c8..932cef5 100644 --- a/src/FDS/GalaxyFDSClient.php +++ b/src/FDS/GalaxyFDSClient.php @@ -831,7 +831,7 @@ public function completeMultipartUpload($bucket_name, $object_name, $upload_id, $metadata, $upload_part_result_list) { $uri = $this->fds_config->getBaseUri() . $bucket_name . "/" . $object_name . "?uploadId=" . $upload_id; - $headers = $this->prepareRequestHeader($uri, Http::PUT, Mime::JSON); + $headers = $this->prepareRequestHeader($uri, Http::PUT, Mime::JSON, $metadata); $response = $this->invoke(Action::CompleteMultipartUpload, $uri, $headers, Http::PUT, null, json_encode($upload_part_result_list)); diff --git a/tests/FDS/FDSClientConfigurationTest.php b/tests/FDS/FDSClientConfigurationTest.php index c06174c..62592ee 100644 --- a/tests/FDS/FDSClientConfigurationTest.php +++ b/tests/FDS/FDSClientConfigurationTest.php @@ -19,7 +19,7 @@ class FDSClientConfigurationTest extends \PHPUnit_Framework_TestCase { public function testDefaultConfigurationValue() { $fds_config = new FDSClientConfiguration(); - $this->assertEquals("", $fds_config->getRegionName()); + $this->assertEquals("cnbj0", $fds_config->getRegionName()); $this->assertEquals(true, $fds_config->isHttpsEnabled()); $this->assertEquals(false, $fds_config->isCdnEnabledForUpload()); $this->assertEquals(true, $fds_config->isCdnEnabledForDownload()); @@ -69,5 +69,14 @@ public function testBuildBaseUri() { $fds_config->enableHttps(false); $this->assertEquals("http://" . $region_name . '.' . self::URI_SUFFIX . '/', $fds_config->buildBaseUri(false)); + + $endpoint = "cnbj1.api.xiaomi.net"; + $fds_config->enableHttps(false); + $fds_config->setEndpoint($endpoint); + $this->assertEquals("http://" . $endpoint . "/", $fds_config->buildBaseUri(false)); + $this->assertEquals("http://" . $endpoint . "/", $fds_config->buildBaseUri(true)); + $fds_config->enableHttps(true); + $this->assertEquals("https://" . $endpoint . "/", $fds_config->buildBaseUri(false)); + $this->assertEquals("https://" . $endpoint . "/", $fds_config->buildBaseUri(true)); } } \ No newline at end of file diff --git a/tests/FDS/GalaxyFDSClientTest.php b/tests/FDS/GalaxyFDSClientTest.php index 050c017..ee9f51e 100644 --- a/tests/FDS/GalaxyFDSClientTest.php +++ b/tests/FDS/GalaxyFDSClientTest.php @@ -19,6 +19,7 @@ use FDS\model\Grant; use FDS\model\Grantee; use FDS\model\Permission; +use FDS\model\UploadPartResultList; use Httpful\Request; class GalaxyFDSClientTest extends \PHPUnit_Framework_TestCase { @@ -422,6 +423,34 @@ public function testPresigedUri() { $this->assertEquals($content_type, $object->getObjectMetadata()->getContentType()); } + /** + * @depends testCreateBucket + */ + public function testMultipartUpload() { + $object_name = "multipart-upload"; + $content = "multipart-upload"; + $initMultipartUploadResult = self::$fds_client->initMultipartUpload(self::$bucket_name, $object_name); + + $uploadPartResult = self::$fds_client->uploadPart(self::$bucket_name, + $object_name, $initMultipartUploadResult->getUploadId(), 1, $content); + + + $uploadPartResultArray = array(); + array_push($uploadPartResultArray, $uploadPartResult); + $uploadPartResultList = new UploadPartResultList(); + $uploadPartResultList->setUploadPartResultList($uploadPartResultArray); + $metadata = new FDSObjectMetadata(); + $metadata->setContentType("text/html"); + + self::$fds_client->completeMultipartUpload(self::$bucket_name, $object_name, + $initMultipartUploadResult->getUploadId(), $metadata, $uploadPartResultList); + + $object = self::$fds_client->getObject(self::$bucket_name, $object_name); + $actualObjectContent = $object->getObjectContent(); + $this->assertEquals($content, $actualObjectContent); + $this->assertEquals("text/html", $object->getObjectMetadata()->getContentType()); + } + private function emptyBucket() { self::$fds_client->deleteObjectsByPrefix(self::$bucket_name, ""); } diff --git a/tests/Httpful/HttpfulTest.php b/tests/Httpful/HttpfulTest.php index 2e2708c..eb47313 100644 --- a/tests/Httpful/HttpfulTest.php +++ b/tests/Httpful/HttpfulTest.php @@ -24,7 +24,7 @@ class HttpfulTest extends \PHPUnit_Framework_TestCase { const TEST_SERVER = TEST_SERVER; - const TEST_URL = '127.0.0.1:8008'; + const TEST_URL = 'http://127.0.0.1:8008'; const TEST_URL_400 = 'http://127.0.0.1:8008/400'; const SAMPLE_JSON_HEADER =