diff --git a/src/Upyun/Api/Form.php b/src/Upyun/Api/Form.php index 549c639..f4086f8 100644 --- a/src/Upyun/Api/Form.php +++ b/src/Upyun/Api/Form.php @@ -23,22 +23,27 @@ public function upload($path, $stream, $params) '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, + for ($i = 0; $i < $this->config->retry; $i++) { + $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; + )); + if ($response->getStatusCode() == 200) { + return true; + } + } + return false; } } diff --git a/src/Upyun/Config.php b/src/Upyun/Config.php index 1b99b6c..ebcf579 100644 --- a/src/Upyun/Config.php +++ b/src/Upyun/Config.php @@ -42,6 +42,11 @@ class Config */ public $sizeBoundary = 31457280; + /** + * @var int 支持 form 上传时重试 + */ + public $retry = 1; + /** * @var int 并行式断点续传的并发数 */