Copying a file or folder
To copy files or folders on Yandex Disk, specify the current path to the resource and the path it should be copied to.
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 being copied>
& path=<path to the copied resource>
& [overwrite=<overwrite flag>]
& [fields=<properties to include in the response>]
- from*
-
The path to the resource being copied. For example,
%2Ffoo%2Fphoto.png
.The path in the parameter value should be encoded in URL format.
- path*
-
The path to the resource copy being created. For example,
%2Fbar%2Fphoto.png
(maximum path length is 32760 characters).The path in the parameter value should be encoded in URL format.
- overwrite
-
Overwrite flag. Used if the resource is copied to a folder that already contains a resource with the same name.
Supported values:
false
: don't overwrite the files and cancel copying. Used by default.true
: copy the resource and delete the existing file with the same name.
- fields
- List of JSON properties to include in the response. Keys not specified in this list are omitted when generating a response. If the parameter isn't specified, the response is returned in full without omitting anything.
Key names should be separated by commas, and embedded keys should be separated by dots. For example:name,_embedded.items.path
.
* Required parameter.
Response format
If the request is processed without errors, the API creates the response body based 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, the relevant response code is returned, and the response body contains an error description.
File or empty folder
The API returns the 201 Created
code (resource successfully copied). The Link object in the response body contains a link to meta information about the created resource.
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 returns the 202 Accepted
code (copying started).
Apps must track the status of requested operations. The API returns a link to the status of the requested operation in the response body within the Link object.
Sample response:
{
"href": "https://cloud-api.yandex.net/v1/disk/operations?id=33ca7d03ab21ct41b4a40182e78d828a3f8b72cdb5f4c0e94cc4b1449a63a2fe",
"method": "GET",
"templated": false
}
Element |
Description |
|
URL. It may be a URL template. See the |
|
The HTTP method for requesting the URL from the |
|
Indicates a URL template according to RFC 6570. Possible values:
|
: The path to the resource being copied. For example, %2Ffoo%2Fphoto.png
.
The path in the parameter value should be encoded in URL format.
The path to the resource copy being created. For example, %2Fbar%2Fphoto.png
(maximum path length is 32760 characters).
The path in the parameter value should be encoded in URL format.
Overwrite flag. Used if the resource is copied to a folder that already contains a resource with the same name.
Supported values:
false
: don't overwrite the files and cancel copying. Used by default.true
: copy the resource and delete the existing file with the same name.
List of JSON properties to include in the response. Keys not specified in this list are omitted when generating a response. If the parameter isn't specified, the response is returned in full without omitting anything.
Key names should be separated by commas, and embedded keys should be separated by dots. For example: name,_embedded.items.path
.
Required parameter.