Copying a file or folder
To copy files and folders on a user's Disk, specify the path to the resource, and the desired path for its copy.
Request format
Use the POST method to send the copy request.
https://cloud-api.yandex.net/v1/disk/resources/copy
? from=<path to the resource to copy>
& path=<path to the resource to copy>
& [overwrite=<overwriting flag>]
& [fields=<properties to include in the response>]
from * | The path to the resource to copy. For example, %2Ffoo%2Fphoto.png. The path in the parameter value should be URL-encoded. |
path * | The path to the copy of the resource that is being created. For example, %2Fbar%2Fphoto.png (the new resource path can be up to 32760 characters long). The path in the parameter value should be URL-encoded. |
overwrite | Whether to overwrite. It is used if the resource is copied to a folder that already contains a resource with the same name. Acceptable values:
|
fields | List of JSON keys to include in the response. Keys that are not included in this list will be discarded when forming the response. If the parameter is omitted, the response is returned in full, without discarding anything. Key names should be comma-separated, and embedded keys should be separated by dots. For example: |
from * | The path to the resource to copy. For example, %2Ffoo%2Fphoto.png. The path in the parameter value should be URL-encoded. |
path * | The path to the copy of the resource that is being created. For example, %2Fbar%2Fphoto.png (the new resource path can be up to 32760 characters long). The path in the parameter value should be URL-encoded. |
overwrite | Whether to overwrite. It is used if the resource is copied to a folder that already contains a resource with the same name. Acceptable values:
|
fields | List of JSON keys to include in the response. Keys that are not included in this list will be discarded when forming the response. If the parameter is omitted, the response is returned in full, without discarding anything. Key names should be comma-separated, and embedded keys should be separated by dots. For example: |
* Required
Response format
If the request was processed without errors, the API composes the response body depending on the type of the specified resource. The response for an empty folder or file is different from the response for a non-empty folder. (If the request caused an error, a relevant response code is returned, with the response body featuring the error description.)
File or empty folder
The API responds with the 201 Created
code (the resource is successfully copied) and returns a link to the metainformation about the created resource in the response body, in the Link object.
Sample response:
{
"href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Ffoo%2Fbar",
"method": "GET",
"templated": false
}
Non-empty folder
Copying a non-empty folder can take some time, so the API responds with the 202 Accepted
code (copying started).
Applications must track the status of requested operations. The Yandex.Disk API returns the link to the status of the operation started by the request. The link is included in the Link object in the response body.
Sample response:
{ "href": "https://cloud-api.yandex.net/v1/disk/operations?id=33ca7d03ab21ct41b4a40182e78d828a3f8b72cdb5f4c0e94cc4b1449a63a2fe", "method": "GET", "templated": false}
Element | Description |
---|---|
href | URL. It may be a URL template; see the |
method | The HTTP method for requesting the URL from the |
templated | Indicates a URL template according to RFC 6570. Possible values:
|
Element | Description |
---|---|
href | URL. It may be a URL template; see the |
method | The HTTP method for requesting the URL from the |
templated | Indicates a URL template according to RFC 6570. Possible values:
|