Conditions | 3 |
Paths | 4 |
Total Lines | 34 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | public function upload($path, $stream, $params) { |
||
11 | $params['save-key'] = $path; |
||
12 | $params['bucket'] = $this->config->bucketName; |
||
13 | if (!isset($params['expiration'])) { |
||
14 | $params['expiration'] = time() + 30 * 60 * 60; // 30 分钟 |
||
15 | } |
||
16 | |||
17 | $result = Signature::getFormSignature($this->config, $params); |
||
18 | $policy = $result['policy']; |
||
19 | $signature = $result['signature']; |
||
20 | $client = new Client([ |
||
21 | 'timeout' => $this->config->timeout, |
||
22 | ]); |
||
23 | |||
24 | $url = ($this->config->useSsl ? 'https://' : 'http://') . $this->endpoint; |
||
25 | |||
26 | $response = $client->request('POST', $url, array( |
||
27 | 'multipart' => array( |
||
28 | array( |
||
29 | 'name' => 'policy', |
||
30 | 'contents' => $policy, |
||
31 | ), |
||
32 | array( |
||
33 | 'name' => 'signature', |
||
34 | 'contents' => $signature, |
||
35 | ), |
||
36 | array( |
||
37 | 'name' => 'file', |
||
38 | 'contents' => $stream, |
||
39 | ) |
||
40 | ) |
||
41 | )); |
||
42 | return $response->getStatusCode() === 200; |
||
43 | } |
||
44 | } |