Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Qcloud/Cos/BucketStyleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function onCommandAfterPrepare(Event $event) {
// Set the key and bucket on the request
$request->getParams()->set('bucket', $bucket)->set('key', $key);

$request->setPath(urldecode($request->getPath()));
//$request->setPath(urldecode($request->getPath()));
// Switch to virtual hosted bucket
$request->setHost($bucket. '.' . $request->getHost());
if (!$bucket) {
Expand Down
8 changes: 5 additions & 3 deletions src/Qcloud/Cos/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ public function upload($bucket, $key, $body, $options = array()) {
return $multipartUpload->performUploading();
}
public function copy($bucket, $key, $copysource, $options = array()) {

$options = Collection::fromConfig(array_change_key_case($options), array(
'min_part_size' => MultipartUpload::MIN_PART_SIZE,
'min_part_size' => Copy::MIN_PART_SIZE,
'params' => $options));
$sourcebucket = explode('-',explode('.',$copysource)[0])[0];
$sourceappid = explode('-',explode('.',$copysource)[0])[1];
$sourceregion = explode('.',$copysource)[2];
$sourcekey = substr(strstr($copysource,'/'),1);
$cosClient = new Client(array('region' => getenv('COS_REGION'),
$cosClient = new Client(array('region' => $sourceregion,
'credentials'=> array(
'appId' => $sourceappid,
'secretId' => $this->secretId,
Expand All @@ -135,8 +136,9 @@ public function copy($bucket, $key, $copysource, $options = array()) {
$rt = $cosClient->headObject(array('Bucket'=>$sourcebucket,
'Key'=>$sourcekey));
$contentlength =$rt['ContentLength'];

if ($contentlength < $options['min_part_size']) {
return $this->UploadPartCopy(array(
return $this->copyObject(array(
'Bucket' => $bucket,
'Key' => $key,
'CopySource' => $copysource,
Expand Down
42 changes: 32 additions & 10 deletions src/Qcloud/Cos/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Copy {
/**
* const var: part size from 5MB to 5GB, and max parts of 10000 are allowed for each upload.
*/
const MIN_PART_SIZE = 5242880;
const MIN_PART_SIZE = 52428800;
const MAX_PART_SIZE = 5368709120;
const MAX_PARTS = 10000;

Expand All @@ -27,6 +27,11 @@ public function __construct($client, $contentlength, $source, $minPartSize, $opt
}

public function performUploading() {

$commands = array();



$uploadId = $this->initiateMultipartUpload();
$offset = 0;
$partNumber = 1;
Expand All @@ -39,22 +44,39 @@ public function performUploading() {
$partSize = $this->size - $offset -1;
}
//echo ('bytes='.( 'bytes='.((string)$offset).'-'.(string)($offset+$partSize)));
$result = $this->client->UploadPartCopy(array(
'Bucket' => $this->options['Bucket'],
'Key' => $this->options['Key'],
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'CopySource'=> $this->source,
'CopySourceRange' => 'bytes='.((string)$offset).'-'.(string)($offset+$partSize)));
$part = array('PartNumber' => $partNumber, 'ETag' => $result['ETag']);
array_push($parts, $part);
$commands[] = $this->client->getCommand('UploadPartCopy', array(
'Bucket' => $this->options['Bucket'],
'Key' => $this->options['Key'],
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'CopySource'=> $this->source,
'CopySourceRange' => 'bytes='.((string)$offset).'-'.(string)($offset+$partSize),
));
// $result = $this->client->UploadPartCopy(array(
// 'Bucket' => $this->options['Bucket'],
// 'Key' => $this->options['Key'],
// 'UploadId' => $uploadId,
// 'PartNumber' => $partNumber,
// 'CopySource'=> $this->source,
// 'CopySourceRange' => 'bytes='.((string)$offset).'-'.(string)($offset+$partSize)));
++$partNumber;
$offset += $partSize;
if ($this->size == $offset+1)
{
break;
}
}
$this->client->execute($commands);


$partNumber = 1;
foreach ($commands as $command) {

$result = $command->getResult();
$part = array('PartNumber' => $partNumber, 'ETag' => $result['ETag']);
array_push($parts, $part);
$partNumber++;
}

return $this->client->completeMultipartUpload(array(
'Bucket' => $this->options['Bucket'],
Expand Down