Skip to content

Commit 75f5783

Browse files
authored
Fix appid (#25)
* fix appid * fix appid * Fix urlencode * fix upload headers
1 parent a97cefa commit 75f5783

File tree

8 files changed

+22
-20
lines changed

8 files changed

+22
-20
lines changed

sample.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#createBucket
2020
try {
21-
$result = $cosClient->createBucket(array('Bucket' => 'testbucket'));
21+
$result = $cosClient->createBucket(array('Bucket' => 'testbucket-1252448703'));
2222
print_r($result);
2323
} catch (\Exception $e) {
2424
echo "$e\n";
@@ -27,11 +27,14 @@
2727
#uploadbigfile
2828
try {
2929
$result = $cosClient->upload(
30-
$bucket='testbucket',
31-
$key = '111.txt',
32-
$body = str_repeat('a', 5* 1024 * 1024));
30+
$bucket='testbucket-1252448703',
31+
$key = '111.txt',
32+
$body = str_repeat('a', 5* 1024 * 1024),
33+
$options = array(
34+
"ACL"=>'private',
35+
'CacheControl' => 'private'));
3336
print_r($result);
34-
} catch (\Exception $e) {
37+
} catch (\Exception $e) {
3538
echo "$e\n";
3639
}
3740

src/Guzzle/Http/Url.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ public function normalizePath()
305305
$results[] = $segment;
306306
}
307307
}
308-
309308
// Combine the normalized parts and add the leading slash if needed
310309
$this->path = ($this->path[0] == '/' ? '/' : '') . implode('/', $results);
311310

src/Qcloud/Cos/BucketStyleListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public function onCommandAfterPrepare(Event $event) {
5858
// Set the key and bucket on the request
5959
$request->getParams()->set('bucket', $bucket)->set('key', $key);
6060

61-
#echo(str_replace("%2F","/",$request->getPath()));
62-
$request->setPath(str_replace("%2F","/",$request->getPath()));
61+
$request->setPath(urldecode($request->getPath()));
6362
// Switch to virtual hosted bucket
6463
$request->setHost($bucket. '.' . $request->getHost());
6564
if (!$bucket) {

src/Qcloud/Cos/Client.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,33 @@ public function getObjectUrl($bucket, $key, $expires = null, array $args = array
9595

9696
return $expires ? $this->createPresignedUrl($request, $expires) : $request->getUrl();
9797
}
98-
public function upload($bucket, $key, $body, $acl = '', $options = array()) {
98+
public function upload($bucket, $key, $body, $options = array()) {
9999
$body = EntityBody::factory($body);
100100
$options = Collection::fromConfig(array_change_key_case($options), array(
101101
'min_part_size' => MultipartUpload::MIN_PART_SIZE,
102-
'params' => array()));
103-
102+
'params' => $options));
103+
print_r($options);
104104
if ($body->getSize() < $options['min_part_size']) {
105105
// Perform a simple PutObject operation
106106
return $this->putObject(array(
107107
'Bucket' => $bucket,
108108
'Key' => $key,
109109
'Body' => $body,
110-
'ACL' => $acl
111110
) + $options['params']);
112111
}
113112

114113
$multipartUpload = new MultipartUpload($this, $body, $options['min_part_size'], array(
115114
'Bucket' => $bucket,
116115
'Key' => $key,
117116
'Body' => $body,
118-
'ACL' => $acl
119117
) + $options['params']);
120118

121119
return $multipartUpload->performUploading();
122120
}
123-
public function copy($bucket, $key, $copysource, $acl = '', $options = array()) {
121+
public function copy($bucket, $key, $copysource, $options = array()) {
124122
$options = Collection::fromConfig(array_change_key_case($options), array(
125123
'min_part_size' => MultipartUpload::MIN_PART_SIZE,
126-
'params' => array()));
124+
'params' => $options));
127125
$sourcebucket = explode('-',explode('.',$copysource)[0])[0];
128126
$sourceappid = explode('-',explode('.',$copysource)[0])[1];
129127
$sourceregion = explode('.',$copysource)[2];
@@ -142,15 +140,13 @@ public function copy($bucket, $key, $copysource, $acl = '', $options = array())
142140
'Bucket' => $bucket,
143141
'Key' => $key,
144142
'CopySource' => $copysource,
145-
'ACL' => $acl
146143
) + $options['params']);
147144
}
148145
$copy = new Copy($this, $contentlength, $copysource, $options['min_part_size'], array(
149146
'Bucket' => $bucket,
150147
'Key' => $key,
151148
'ContentLength' => $contentlength,
152149
'CopySource' => $copysource,
153-
'ACL' => $acl
154150
) + $options['params']);
155151

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

164160
public static function explodeKey($key) {
165161
// Remove a leading slash if one is found
166-
//print_r(explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key));
167162
//return explode('/', $key && $key[0] == '/' ? substr($key, 1) : $key);
168163
return $key;
164+
return ltrim($key, "/");
169165
}
170166
}

src/Qcloud/Cos/Command.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ public function createPresignedUrl($expires)
2626

2727
protected function process() {
2828
parent::process();
29-
3029
// Set the GetObject URL if using the PutObject operation
3130
if ($this->result instanceof Model && $this->getName() == 'PutObject') {
32-
$request = $this->getRequest();
31+
$request = $this->getRequest();;
3332
$this->result->set('ObjectURL', $request->getUrl());
3433
}
3534
}

src/Qcloud/Cos/Service.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,10 @@ public static function getService() {
756756
'required' => true,
757757
'type' => 'string',
758758
'location' => 'uri'),
759+
'CacheControl' => array(
760+
'type' => 'string',
761+
'location' => 'header',
762+
'sentAs' => 'Cache-Control'),
759763
'ContentDisposition' => array(
760764
'type' => 'string',
761765
'location' => 'header',

src/Qcloud/Cos/Signature.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __destruct() {
1717
}
1818

1919
public function signRequest(RequestInterface $request) {
20+
2021
$signTime = (string)(time() - 60) . ';' . (string)(time() + 3600);
2122
$httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) .
2223
"\n\nhost=" . $request->getHost() . "\n";

src/Qcloud/Cos/Tests/ObjectTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ protected function setUp() {
1313

1414
$this->cosClient = new Client(array('region' => getenv('COS_REGION'),
1515
'credentials'=> array(
16+
# 'appId' => getenv('COS_APPID'),
1617
'secretId' => getenv('COS_KEY'),
1718
'secretKey' => getenv('COS_SECRET'))));
1819
}

0 commit comments

Comments
 (0)