| Conditions | 2 |
| Paths | 2 |
| Total Lines | 32 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 28 |
| CRAP Score | 2 |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | } |
||
| 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 | 1 | 'multipart' => array( |
|
| 28 | 1 | array( |
|
| 29 | 1 | 'name' => 'policy', |
|
| 30 | 1 | 'contents' => $policy, |
|
| 31 | 1 | ), |
|
| 32 | 1 | array( |
|
| 33 | 1 | 'name' => 'authorization', |
|
| 34 | 1 | 'contents' => $signature, |
|
| 35 | 1 | ), |
|
| 36 | 1 | array( |
|
| 37 | 1 | 'name' => 'file', |
|
| 38 | 1 | 'contents' => $stream, |
|
| 39 | 1 | ) |
|
| 40 | 1 | ) |
|
| 41 | 1 | )); |
|
| 42 | 1 | return $response->getStatusCode() === 200; |
|
| 43 | } |
||
| 45 |