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
13 changes: 8 additions & 5 deletions sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#createBucket
try {
$result = $cosClient->createBucket(array('Bucket' => 'testbucket'));
$result = $cosClient->createBucket(array('Bucket' => 'testbucket-1252448703'));
print_r($result);
} catch (\Exception $e) {
echo "$e\n";
Expand All @@ -27,11 +27,14 @@
#uploadbigfile
try {
$result = $cosClient->upload(
$bucket='testbucket',
$key = '111.txt',
$body = str_repeat('a', 5* 1024 * 1024));
$bucket='testbucket-1252448703',
$key = '111.txt',
$body = str_repeat('a', 5* 1024 * 1024),
$options = array(
"ACL"=>'private',
'CacheControl' => 'private'));
print_r($result);
} catch (\Exception $e) {
} catch (\Exception $e) {
echo "$e\n";
}

Expand Down
1 change: 0 additions & 1 deletion src/Guzzle/Http/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ public function normalizePath()
$results[] = $segment;
}
}

// Combine the normalized parts and add the leading slash if needed
$this->path = ($this->path[0] == '/' ? '/' : '') . implode('/', $results);

Expand Down
3 changes: 1 addition & 2 deletions src/Qcloud/Cos/BucketStyleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function onCommandAfterPrepare(Event $event) {
// Set the key and bucket on the request
$request->getParams()->set('bucket', $bucket)->set('key', $key);

#echo(str_replace("%2F","/",$request->getPath()));
$request->setPath(str_replace("%2F","/",$request->getPath()));
$request->setPath(urldecode($request->getPath()));
// Switch to virtual hosted bucket
$request->setHost($bucket. '.' . $request->getHost());
if (!$bucket) {
Expand Down
16 changes: 6 additions & 10 deletions src/Qcloud/Cos/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,33 @@ public function getObjectUrl($bucket, $key, $expires = null, array $args = array

return $expires ? $this->createPresignedUrl($request, $expires) : $request->getUrl();
}
public function upload($bucket, $key, $body, $acl = '', $options = array()) {
public function upload($bucket, $key, $body, $options = array()) {
$body = EntityBody::factory($body);
$options = Collection::fromConfig(array_change_key_case($options), array(
'min_part_size' => MultipartUpload::MIN_PART_SIZE,
'params' => array()));

'params' => $options));
print_r($options);
if ($body->getSize() < $options['min_part_size']) {
// Perform a simple PutObject operation
return $this->putObject(array(
'Bucket' => $bucket,
'Key' => $key,
'Body' => $body,
'ACL' => $acl
) + $options['params']);
}

$multipartUpload = new MultipartUpload($this, $body, $options['min_part_size'], array(
'Bucket' => $bucket,
'Key' => $key,
'Body' => $body,
'ACL' => $acl
) + $options['params']);

return $multipartUpload->performUploading();
}
public function copy($bucket, $key, $copysource, $acl = '', $options = array()) {
public function copy($bucket, $key, $copysource, $options = array()) {
$options = Collection::fromConfig(array_change_key_case($options), array(
'min_part_size' => MultipartUpload::MIN_PART_SIZE,
'params' => array()));
'params' => $options));
$sourcebucket = explode('-',explode('.',$copysource)[0])[0];
$sourceappid = explode('-',explode('.',$copysource)[0])[1];
$sourceregion = explode('.',$copysource)[2];
Expand All @@ -142,15 +140,13 @@ public function copy($bucket, $key, $copysource, $acl = '', $options = array())
'Bucket' => $bucket,
'Key' => $key,
'CopySource' => $copysource,
'ACL' => $acl
) + $options['params']);
}
$copy = new Copy($this, $contentlength, $copysource, $options['min_part_size'], array(
'Bucket' => $bucket,
'Key' => $key,
'ContentLength' => $contentlength,
'CopySource' => $copysource,
'ACL' => $acl
) + $options['params']);

return $copy->performUploading();
Expand All @@ -163,8 +159,8 @@ public static function encodeKey($key) {

public static function explodeKey($key) {
// Remove a leading slash if one is found
//print_r(explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key));
//return explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key);
return $key;
return ltrim($key, "/");
}
}
3 changes: 1 addition & 2 deletions src/Qcloud/Cos/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public function createPresignedUrl($expires)

protected function process() {
parent::process();

// Set the GetObject URL if using the PutObject operation
if ($this->result instanceof Model && $this->getName() == 'PutObject') {
$request = $this->getRequest();
$request = $this->getRequest();;
$this->result->set('ObjectURL', $request->getUrl());
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Qcloud/Cos/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,10 @@ public static function getService() {
'required' => true,
'type' => 'string',
'location' => 'uri'),
'CacheControl' => array(
'type' => 'string',
'location' => 'header',
'sentAs' => 'Cache-Control'),
'ContentDisposition' => array(
'type' => 'string',
'location' => 'header',
Expand Down
1 change: 1 addition & 0 deletions src/Qcloud/Cos/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __destruct() {
}

public function signRequest(RequestInterface $request) {

$signTime = (string)(time() - 60) . ';' . (string)(time() + 3600);
$httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) .
"\n\nhost=" . $request->getHost() . "\n";
Expand Down
1 change: 1 addition & 0 deletions src/Qcloud/Cos/Tests/ObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected function setUp() {

$this->cosClient = new Client(array('region' => getenv('COS_REGION'),
'credentials'=> array(
# 'appId' => getenv('COS_APPID'),
'secretId' => getenv('COS_KEY'),
'secretKey' => getenv('COS_SECRET'))));
}
Expand Down