Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Qiniu/Storage/BucketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,28 @@ public function changeMime($bucket, $key, $mime)
* @param $bucket 目标资源空间
* @param $key 目标资源文件名
*
* @return 成功返回NULL,失败返回对象{"error" => "<errMsg string>", ...}
* @return array[] 包含已拉取的文件信息。
* 成功时: [
* [
* "hash" => "<Hash string>",
* "key" => "<Key string>"
* ],
* null
* ]
*
* 失败时: [
* null,
* Qiniu/Http/Error
* ]
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html
*/
public function fetch($url, $bucket, $key)
{

$resource = \Qiniu\base64_urlSafeEncode($url);
$to = \Qiniu\entry($bucket, $key);
$path = '/fetch/' . $resource . '/to/' . $to;
list($_, $error) = $this->ioPost($path);
return $error;
return $this->ioPost($path);
}

/**
Expand Down
11 changes: 10 additions & 1 deletion tests/Qiniu/Tests/BucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,20 @@ public function testPrefetch()

public function testFetch()
{
$error = $this->bucketManager->fetch(
list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName,
'fetch.html'
);
$this->assertArrayHasKey('hash', $ret);
$this->assertNull($error);

list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName,
''
);
$this->assertArrayHasKey('key', $ret);
$this->assertNull($error);
}

Expand Down