Completed
Push — master ( bfc0cc...f0e226 )
by sabaku
04:05
created

Form   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B upload() 0 34 3
1
<?php
2
3
namespace Upyun\Api;
4
5
use Upyun\Signature;
6
use GuzzleHttp\Client;
7
8
class Form extends Rest{
9
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
}