Restoring a file or folder from Trash

If you moved something to Trash, you can restore it to its original location. To do that, enter the resource path to Trash. You can rename the restored resource.

If the file was in a folder that doesn't exist any more, this folder is created in the old location again. For example, if the disk is empty and you restore a file that previously was in the /foo/bar/ folder, the folders foo and bar will be created.

Request format

Use the PUT method to send a request for restoring a file or folder.

https://cloud-api.yandex.net/v1/disk/trash/resources/restore
 ? path=<path to the resource being restored>
 & [name=<new name of the resource being restored>]
 & [overwrite=<overwrite flag>]
path*

The path to the resource being restored relative to the Trash root directory. For example, %2Fbar%2Fphoto.png.

The path in the parameter value should be encoded in URL format.

name

The new name of the resource being restored. For example, selfie.png.

overwrite

Overwrite flag. Used if the resource is restored to a folder that already contains a resource with the same name.

Supported values:

  • false: don't overwrite the files and cancel restoring. Used by default.
  • true: restore the resource and delete the existing file with the same name.

* Required parameter.

Response format

Restoring a resource from Trash may take some time. Depending on the operation status, the Yandex Disk server returns one of the two responses:

  • If the request is processed without errors, the API returns the 201 Created code (resource successfully moved). The response body contains the link to the created resource's meta information within the Link object.

    Sample response:

    {
    "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fselfie.png",
    "method": "GET",
    "templated": false
    }
    
  • If saving has started but not completed yet, Yandex Disk returns the 202 Accepted code.

    Apps must track the status of requested operations. Yandex Disk returns a link to the status of the requested operation within the Link object in the response body.

    Sample response:

    {
    "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2F%D0%97%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B8%photo.png",
    "method": "GET",
    "templated": false
    }
    

    Element

    Description

    href

    URL. It may be a URL template. See the templated key.

    method

    The HTTP method for requesting the URL from the href key.

    templated

    Indicates a URL template according to RFC 6570. Possible values:

    • "true" — URL template. To send a request to this address, replace the placeholder values in the curly brackets with the parameter values.
    • "false" — The URL can be requested without changes.

If the request caused an error, the relevant response code is returned, and the response body contains an error description.

The path to the resource being restored relative to the Trash root directory. For example, %2Fbar%2Fphoto.png.

The path in the parameter value should be encoded in URL format.

The new name of the resource being restored. For example, selfie.png.

Overwrite flag. Used if the resource is restored to a folder that already contains a resource with the same name.

Supported values:

  • false: don't overwrite the files and cancel restoring. Used by default.
  • true: restore the resource and delete the existing file with the same name.

Required parameter.