Conditions | 2 |
Paths | 2 |
Total Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Tests | 24 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
11 | 1 | public function upload($path, $stream, $params) |
|
12 | { |
||
13 | 1 | $params['save-key'] = $path; |
|
14 | 1 | $params['service'] = $this->config->serviceName; |
|
15 | 1 | if (!isset($params['expiration'])) { |
|
16 | 1 | $params['expiration'] = time() + 30 * 60 * 60; // 30 分钟 |
|
17 | 1 | } |
|
18 | |||
19 | 1 | $policy = Util::base64Json($params); |
|
20 | 1 | $method = 'POST'; |
|
21 | 1 | $signature = Signature::getBodySignature($this->config, $method, '/' . $params['service'], null, $policy); |
|
22 | 1 | $client = new Client([ |
|
23 | 1 | 'timeout' => $this->config->timeout, |
|
24 | 1 | ]); |
|
25 | |||
26 | 1 | $response = $client->request($method, $this->endpoint, array( |
|
27 | 'multipart' => array( |
||
28 | array( |
||
29 | 1 | 'name' => 'policy', |
|
30 | 1 | 'contents' => $policy, |
|
31 | 1 | ), |
|
32 | array( |
||
33 | 1 | 'name' => 'authorization', |
|
34 | 1 | 'contents' => $signature, |
|
35 | 1 | ), |
|
36 | array( |
||
37 | 1 | 'name' => 'file', |
|
38 | 1 | 'contents' => $stream, |
|
39 | ) |
||
40 | 1 | ) |
|
41 | 1 | )); |
|
42 | 1 | return $response->getStatusCode() === 200; |
|
43 | } |
||
44 | } |
||
45 |