-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
600 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
require_once __DIR__ . '/Common.php'; | ||
|
||
use OSS\OssClient; | ||
use OSS\Core\OssException; | ||
|
||
$bucket = Common::getBucketName(); | ||
$ossClient = Common::getOssClient(); | ||
if (is_null($ossClient)) exit(1); | ||
//*******************************简单使用*************************************************************** | ||
|
||
/** putObject 使用callback上传内容到oss文件 | ||
* callbackurl参数指定请求回调的服务器url | ||
* callbackbodytype参数可为application/json或application/x-www-form-urlencoded, 可选参数,默认为application/x-www-form-urlencoded | ||
* OSS_CALLBACK_VAR参数可以不设置 | ||
*/ | ||
$url = | ||
'{ | ||
"callbackUrl":"callback.oss-demo.com:23450", | ||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com", | ||
"callbackBody":"bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&imageInfo.height=${imageInfo.height}&imageInfo.width=${imageInfo.width}&imageInfo.format=${imageInfo.format}&my_var1=${x:var1}&my_var2=${x:var2}", | ||
"callbackBodyType":"application/x-www-form-urlencoded" | ||
}'; | ||
$var = | ||
'{ | ||
"x:var1":"value1", | ||
"x:var2":"值2" | ||
}'; | ||
$options = array(OssClient::OSS_CALLBACK => $url, | ||
OssClient::OSS_CALLBACK_VAR => $var | ||
); | ||
$result = $ossClient->putObject($bucket, "b.file", "random content", $options); | ||
Common::println($result['body']); | ||
Common::println($result['info']['http_code']); | ||
/** | ||
* completeMultipartUpload 使用callback上传内容到oss文件 | ||
* callbackurl参数指定请求回调的服务器url | ||
* callbackbodytype参数可为application/json或application/x-www-form-urlencoded, 可选参数,默认为application/x-www-form-urlencoded | ||
* OSS_CALLBACK_VAR参数可以不设置 | ||
*/ | ||
$object = "multipart-callback-test.txt"; | ||
$copiedObject = "multipart-callback-test.txt.copied"; | ||
$ossClient->putObject($bucket, $copiedObject, file_get_contents(__FILE__)); | ||
/** | ||
* step 1. 初始化一个分块上传事件, 也就是初始化上传Multipart, 获取upload id | ||
*/ | ||
$upload_id = $ossClient->initiateMultipartUpload($bucket, $object); | ||
/* | ||
* step 2. uploadPartCopy | ||
*/ | ||
$copyId = 1; | ||
$eTag = $ossClient->uploadPartCopy($bucket, $copiedObject, $bucket, $object, $copyId, $upload_id); | ||
$upload_parts[] = array( | ||
'PartNumber' => $copyId, | ||
'ETag' => $eTag, | ||
); | ||
$listPartsInfo = $ossClient->listParts($bucket, $object, $upload_id); | ||
/** | ||
* step 3. | ||
*/ | ||
$json = | ||
'{ | ||
"callbackUrl":"callback.oss-demo.com:23450", | ||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com", | ||
"callbackBody":"{\"mimeType\":${mimeType},\"size\":${size},\"x:var1\":${x:var1},\"x:var2\":${x:var2}}", | ||
"callbackBodyType":"application/json" | ||
}'; | ||
|
||
$var = | ||
'{ | ||
"x:var1":"value1", | ||
"x:var2":"值2" | ||
}'; | ||
$options = array(OssClient::OSS_CALLBACK => $json, | ||
OssClient::OSS_CALLBACK_VAR => $var); | ||
|
||
$result = $ossClient->completeMultipartUpload($bucket, $object, $upload_id, $upload_parts, $options); | ||
Common::println($result['body']); | ||
Common::println($result['info']['http_code']); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace OSS\Result; | ||
|
||
|
||
/** | ||
* Class CallbackResult | ||
* @package OSS\Result | ||
*/ | ||
class CallbackResult extends PutSetDeleteResult | ||
{ | ||
protected function isResponseOk() | ||
{ | ||
$status = $this->rawResponse->status; | ||
if ((int)(intval($status) / 100) == 2 && (int)(intval($status)) !== 203) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace OSS\Result; | ||
|
||
|
||
/** | ||
* Class CopyObjectResult | ||
* @package OSS\Result | ||
*/ | ||
class CopyObjectResult extends Result | ||
{ | ||
/** | ||
* @return array() | ||
*/ | ||
protected function parseDataFromResponse() | ||
{ | ||
$body = $this->rawResponse->body; | ||
$xml = simplexml_load_string($body); | ||
$result = array(); | ||
|
||
if (isset($xml->LastModified)) { | ||
$result[] = $xml->LastModified; | ||
} | ||
if (isset($xml->ETag)) { | ||
$result[] = $xml->ETag; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace OSS\Result; | ||
|
||
|
||
/** | ||
* Class DeleteObjectsResult | ||
* @package OSS\Result | ||
*/ | ||
class DeleteObjectsResult extends Result | ||
{ | ||
/** | ||
* @return array() | ||
*/ | ||
protected function parseDataFromResponse() | ||
{ | ||
$body = $this->rawResponse->body; | ||
$xml = simplexml_load_string($body); | ||
$objects = array(); | ||
|
||
if (isset($xml->Deleted)) { | ||
foreach($xml->Deleted as $deleteKey) | ||
$objects[] = $deleteKey->Key; | ||
} | ||
return $objects; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.