Object接口 > 批量操作 | |||||||||||||||||||||||||||
批量操作意指在单一请求中执行多次获取元信息、移动、复制、删除操作,极大提高资源管理效率。 请求报文请求地址:
POST /batch HTTP/1.1 Host: rs.qiniu.com Content-Type: application/x-www-form-urlencoded Authorization: QBox <AccessToken> op=<Operation>&op=<Operation>&... 注意:要在 Authorization 头部的
管理凭证方式。
#批量获取元信息 op=/stat/<EncodedEntryURI>&op=/stat/<EncodedEntryURI>&... #批量复制资源 op=/copy/<EncodedEntryURISrc>/<EncodedEntryURIDest>&op=/copy/<EncodedEntryURISrc>/<EncodedEntryURIDest>&.../force/<true|false> #批量移动资源 op=/move/<EncodedEntryURISrc>/<EncodedEntryURIDest>&op=/move/<EncodedEntryURISrc>/<EncodedEntryURIDest>&.../force/<true|false> #批量删除资源 op=/delete/<EncodedEntryURI>&op=/delete/<EncodedEntryURI>&... #混合多种操作 op=/stat/<EncodedEntryURI>&op=/copy/<EncodedEntryURISrc>/<EncodedEntryURIDest>/force/<true|false>&op=/move/<EncodedEntryURISrc>/<EncodedEntryURIDest>&.../force/<true|false> &op=/delete/<EncodedEntryURI>&... 响应报文
HTTP/1.1 200 OK Content-Type: application/json Cache-Control: no-store
#批量获取元信息 [ { "code": <HttpCode int>, "data": <Data> }, { "code": <HttpCode int>, "data": <Data> }, { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } }, ... ] #批量复制资源 [ { "code": <HttpCode int> }, { "code": <HttpCode int> }, { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } }, ... ] #批量移动资源 [ { "code": <HttpCode int> }, { "code": <HttpCode int> }, { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } }, ... ] #批量删除资源 [ { "code": <HttpCode int> }, { "code": <HttpCode int> }, { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } }, ... ] #混合多种操作 [ { "code": <HttpCode int>, "data": <Data> }, { "code": <HttpCode int> }, { "code": <HttpCode int> }, { "code": <HttpCode int> }, { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } }, ... ]
示例functon deletebatchfile($accessKeyk, $secretKey, $bucket, $keys) { $authObj = new Auth($accessKey, $secretKey); $http = new Http(); //生成批量删除资源body $body = ''; foreach ($keys as $key) { if ($body == '') { $body .= 'op=/delete/' . $authObj->entry($bucket, $key); } else { $body .= '&op=/delete/' . $authObj->entry($bucket, $key); } } $url = "http://rs.qiniu.com/batch"; $headers = $authObj->getHeaders($url, $body, 'application/x-www-form-urlencoded'); // 创建一个新cURL资源 $curl = curl_init(); // 设置URL和相应的选项 curl_setopt($curl, CURLOPT_URL, $url); //CURLOPT_HEADER为true设置头文件的信息作为数据流输出 curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper('POST')); curl_setopt($curl, CURLOPT_POST, true); $result = curl_exec($curl); curl_close($curl); return $result; } $accessKey = 'xxx'; $secretKey = 'xxx'; $bucket = '123_1';//存储空间名称 $keys = ['132.jpg', 'index.php']; //文件列表 echo deletebatchfile($accessKeyk, $secretKey, $bucket, $keys); |