帮助与文档

全部文档

批量操作

    批量操作意指在单一请求中执行多次获取元信息、移动、复制、删除操作,极大提高资源管理效率。

    请求报文

    请求地址:

    rs.qiniu.com

    • 请求语法
    1. POST /batch HTTP/1.1
    2. Host: rs.qiniu.com
    3. Content-Type: application/x-www-form-urlencoded
    4. Authorization: QBox <AccessToken>
    5. op=<Operation>&op=<Operation>&...

    注意:要在 Authorization 头部的<AccessToken>前添加 QBox 和半角空格。其中op=<Operation>是单一资源管理指令(如:/stat/<EncodeEntryURI>/delete/<EncodeEntryURI>)。

    • 访问权限

    管理凭证方式。

    • 头部信息
    头部名称 必填 说明
    Content-Type 固定为 application/x-www-form-urlencoded
    Authorization 该参数应严格按照管理凭证格式进行填充,否则会返回401错误码
    一个合法的 Authorization 值应类似于:QBox QNJi_bYJlmO5LeY08FfoNj9w_r7..
    • 请求内容
    1. #批量获取元信息
    2. op=/stat/<EncodedEntryURI>&op=/stat/<EncodedEntryURI>&...
    3. #批量复制资源
    4. op=/copy/<EncodedEntryURISrc>/<EncodedEntryURIDest>&op=/copy/<EncodedEntryURISrc>/<EncodedEntryURIDest>&.../force/<true|false>
    5. #批量移动资源
    6. op=/move/<EncodedEntryURISrc>/<EncodedEntryURIDest>&op=/move/<EncodedEntryURISrc>/<EncodedEntryURIDest>&.../force/<true|false>
    7. #批量删除资源
    8. op=/delete/<EncodedEntryURI>&op=/delete/<EncodedEntryURI>&...
    9. #混合多种操作
    10. op=/stat/<EncodedEntryURI>&op=/copy/<EncodedEntryURISrc>/<EncodedEntryURIDest>/force/<true|false>&op=/move/<EncodedEntryURISrc>/<EncodedEntryURIDest>&.../force/<true|false> &op=/delete/<EncodedEntryURI>&...

    响应报文

    • 响应语法
    1. HTTP/1.1 200 OK
    2. Content-Type: application/json
    3. Cache-Control: no-store
    • 头部信息
    头部名称 必填 说明
    Content-Type 正常情况下该值将被设为application/json,表示返回JSON格式的文本信息。
    • 响应内容
    1. #批量获取元信息
    2. [
    3. { "code": <HttpCode int>, "data": <Data> },
    4. { "code": <HttpCode int>, "data": <Data> },
    5. { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } },
    6. ...
    7. ]
    8. #批量复制资源
    9. [
    10. { "code": <HttpCode int> },
    11. { "code": <HttpCode int> },
    12. { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } },
    13. ...
    14. ]
    15. #批量移动资源
    16. [
    17. { "code": <HttpCode int> },
    18. { "code": <HttpCode int> },
    19. { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } },
    20. ...
    21. ]
    22. #批量删除资源
    23. [
    24. { "code": <HttpCode int> },
    25. { "code": <HttpCode int> },
    26. { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } },
    27. ...
    28. ]
    29. #混合多种操作
    30. [
    31. { "code": <HttpCode int>, "data": <Data> },
    32. { "code": <HttpCode int> },
    33. { "code": <HttpCode int> },
    34. { "code": <HttpCode int> },
    35. { "code": <HttpCode int>, "data": { "error": "<ErrorMessage string>" } },
    36. ...
    37. ]
    • 响应状态码
    HTTP状态码 含义
    200 所有请求操作都已成功完成
    298 部分或所有请求操作失败
    400 请求报文格式错误
    401 管理凭证无效
    599 服务端操作失败

    示例

    1. functon deletebatchfile($accessKeyk, $secretKey, $bucket, $keys){
    2. $authObj = new Auth($accessKey, $secretKey);
    3. $http = new Http();
    4. //生成批量删除资源body
    5. $body = '';
    6. foreach ($keys as $key) {
    7. if ($body == '') {
    8. $body .= 'op=/delete/' . $authObj->entry($bucket, $key);
    9. } else {
    10. $body .= '&op=/delete/' . $authObj->entry($bucket, $key);
    11. }
    12. }
    13. $url = "http://rs.qiniu.com/batch";
    14. $headers = $authObj->getHeaders($url, $body, 'application/x-www-form-urlencoded');
    15. // 创建一个新cURL资源
    16. $curl = curl_init();
    17. // 设置URL和相应的选项
    18. curl_setopt($curl, CURLOPT_URL, $url);
    19. //CURLOPT_HEADER为true设置头文件的信息作为数据流输出
    20. curl_setopt($curl, CURLOPT_HEADER, false);
    21. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    22. curl_setopt($curl, CURLOPT_TIMEOUT, 60);
    23. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    24. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper('POST'));
    25. curl_setopt($curl, CURLOPT_POST, true);
    26. $result = curl_exec($curl);
    27. curl_close($curl);
    28. return $result;
    29. }
    30. $accessKey = 'xxx';
    31. $secretKey = 'xxx';
    32. $bucket = '123_1';//存储空间名称
    33. $keys = ['132.jpg', 'index.php']; //文件列表
    34. echo deletebatchfile($accessKeyk, $secretKey, $bucket, $keys);

    这条帮助是否解决了您的问题? 已解决 未解决

    提交成功!非常感谢您的反馈,我们会继续努力做到更好!更多建议 非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

    在文档使用中是否遇到以下问题:

    更多建议