Skip to content

Commit 65f569d

Browse files
committed
support multi up zone
1 parent ca1d6ac commit 65f569d

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

Zone.php

Whitespace-only changes.

src/Qiniu/Config.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ final class Config
55
{
66
const SDK_VER = '7.0.2';
77

8+
const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,暂不支持修改
9+
810
const IO_HOST = 'http://iovip.qbox.me'; // 七牛源站Host
911
const RS_HOST = 'http://rs.qbox.me'; // 文件元信息管理操作Host
1012
const RSF_HOST = 'http://rsf.qbox.me'; // 列举操作Host
1113
const API_HOST = 'http://api.qiniu.com'; // 数据处理操作Host
1214

13-
const UPAUTO_HOST = 'http://up.qiniu.com'; // 默认上传Host
14-
const UPDX_HOST = 'http://updx.qiniu.com'; // 电信上传Host
15-
const UPLT_HOST = 'http://uplt.qiniu.com'; // 联通上传Host
16-
const UPYD_HOST = 'http://upyd.qiniu.com'; // 移动上传Host
17-
const UPBACKUP_HOST = 'http://upload.qiniu.com'; // 备用上传Host
15+
public static $upHost = 'http://up.qiniu.com'; // 默认上传Host
16+
public static $zone; // 设置上传的Zone
1817

19-
const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,暂不支持修改
18+
public function __construct(Zone $zone=null) { // 构造函数,默认为zone0
19+
if ($zone!==null) {
20+
self::$zone = $zone;
21+
self::$upHost = self::$zone->upHost;
22+
}
23+
return;
24+
}
2025

21-
public static $defaultHost = self::UPAUTO_HOST; // 设置为默认上传Host
2226
}

src/Qiniu/Storage/FormUploader.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static function put(
1111
$upToken,
1212
$key,
1313
$data,
14+
$config,
1415
$params,
1516
$mime,
1617
$checkCrc
@@ -31,9 +32,9 @@ public static function put(
3132
}
3233
}
3334

34-
$response = Client::multipartPost(Config::$defaultHost, $fields, 'file', $fname, $data, $mime);
35+
$response = Client::multipartPost($config::$upHost, $fields, 'file', $fname, $data, $mime);
3536
if (!$response->ok()) {
36-
return array(null, new Error(Config::$defaultHost, $response));
37+
return array(null, new Error($config::$upHost, $response));
3738
}
3839
return array($response->json(), null);
3940
}
@@ -42,6 +43,7 @@ public static function putFile(
4243
$upToken,
4344
$key,
4445
$filePath,
46+
$config,
4547
$params,
4648
$mime,
4749
$checkCrc
@@ -63,9 +65,9 @@ public static function putFile(
6365
}
6466
}
6567
$headers =array('Content-Type' => 'multipart/form-data');
66-
$response = client::post(Config::$defaultHost, $fields, $headers);
68+
$response = client::post($config::$upHost, $fields, $headers);
6769
if (!$response->ok()) {
68-
return array(null, new Error(Config::$defaultHost, $response));
70+
return array(null, new Error($config::$upHost, $response));
6971
}
7072
return array($response->json(), null);
7173
}

src/Qiniu/Storage/UploadManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
*/
1414
final class UploadManager
1515
{
16-
public function __construct()
16+
public $config;
17+
18+
public function __construct($config = null)
1719
{
20+
if ($config === null) {
21+
$config = new Config();
22+
}
23+
$this->config = $config;
1824
}
1925

2026
/**
@@ -47,6 +53,7 @@ public function put(
4753
$upToken,
4854
$key,
4955
$data,
56+
$this->config,
5057
$params,
5158
$mime,
5259
$checkCrc
@@ -96,6 +103,7 @@ public function putFile(
96103
$upToken,
97104
$key,
98105
$data,
106+
$this->config,
99107
$params,
100108
$mime,
101109
$checkCrc

0 commit comments

Comments
 (0)