Object接口 > 资源移动/重命名 | ||||||||||||||||||||||||||||||||
将源空间的指定资源移动到目标空间,或在同一空间内对资源重命名。如果目标资源名已被占用,则返回错误码614,且不做任何覆盖操作。 注意:
请求报文请求地址:
POST /move/<EncodedEntryURISrc>/<EncodedEntryURIDest>/force/<true|false> HTTP/1.1 Host: rs.qiniu.com Content-Type: application/x-www-form-urlencoded Authorization: QBox <AccessToken>
管理凭证方式。
响应报文
HTTP/1.1 200 OK Content-Type: application/json Cache-Control: no-store
如果请求成功,不返回任何内容。 如果请求失败,返回包含如下内容的JSON字符串 { "error": "<errMsg string>", }
请求示例: POST /move/bmV3ZG9jczpmaW5kX21hbi50eHQ=/bmV3ZG9jczpmaW5kLm1hbi50eHQ= HTTP/1.1 User-Agent: curl/7.30.0 Host: rs.qiniu.com Accept: */* Authorization: Qiniu u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:2LJIG.. 响应示例: HTTP/1.1 200 OK Server: nginx/1.0.8 Date: Thu, 05 Dec 2019 11:55:29 GMT Content-Type: application/json Connection: keep-alive Content-Length: 0 X-Reqid: wxIAAD3btw-v3TwT 示例function moveFile ($ak,$sk,$from_bucket,$from_key,$to_bucket,$to_key) { $authObj = new Auth($ak, $sk); $http = new Http(); //生成url $from = $authObj->entry($from_bucket, $from_key); $to = $authObj->entry($to_bucket, $to_key); $path = '/move/' . $from . '/' . $to; if ($force) { $path .= '/force/true'; } $url = "http://rs.qiniu.com{$path}"; $headers = $authObj->getHeaders($url, null, '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; } $ak = 'xxx'; $sk = 'xxx'; //如果是重命名文件,则$from_bucket和$to_bucket是同一个值 $from_bucket = '123_1';//待操作资源所在空间 $from_key = 'QQ图片20200605093453.jpg';//待操作资源文件名 $to_bucket = '123_5';//目标资源空间名 $to_key = 'QQ图片20200605093453.jpg';//目标资源文件名 $force = false; //true:强制覆盖 false:不覆盖 echo moveFile($ak,$sk,$from_bucket,$from_key,$to_bucket,$to_key,$force = false); |