Form.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Upyun\Api;
use Upyun\Signature;
use Upyun\Util;
use GuzzleHttp\Client;
class Form extends Rest
{
public function upload($path, $stream, $params)
{
$params['save-key'] = $path;
$params['service'] = $this->config->serviceName;
if (!isset($params['expiration'])) {
$params['expiration'] = time() + 30 * 60 * 60; // 30 分钟
}
$policy = Util::base64Json($params);
$method = 'POST';
$signature = Signature::getBodySignature($this->config, $method, '/' . $params['service'], null, $policy);
$client = new Client([
'timeout' => $this->config->timeout,
]);
$response = $client->request($method, $this->endpoint, array(
'multipart' => array(
array(
'name' => 'policy',
'contents' => $policy,
),
array(
'name' => 'authorization',
'contents' => $signature,
),
array(
'name' => 'file',
'contents' => $stream,
)
)
));
return $response->getStatusCode() === 200;
}
}