Downloading a file from the internet to Yandex.Disk

Yandex.Disk can download a file to the user's Disk. To do this, pass the file URL in the request and track the progress of the operation. If an error occurs during the download, Yandex.Disk doesn't reattempt the download again.

If the file fails to download directly to Yandex.Disk, you can try downloading it yourself and uploading it with the Upload a file to Disk request.

Request format

Use the POST method to send the download request.

https://cloud-api.yandex.net/v1/disk/resources/upload
 ? url=<link to the file to download>
 & path=<path to the folder to download the file to>
 & [fields=<properties to include in the response>]
 & [disable_redirects=<whether redirects are forbidden>]
Query parameters
url *

Link to the file to download. For example, http%3A%2F%2Fexample.com%2Fphoto.png. The name of the uploaded file can be up to 255 characters. The path can be up to 32760 characters long.

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

path *

The path on Yandex.Disk where the downloaded file should be available. For example, disk%3A%2Fbar%2Fphoto.png.

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

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: name, _embedded. items. path.

disable_redirects

Use this parameter to disable redirects for the address specified in the url parameter.

Acceptable values:

  • “false” — If a redirect is detected, Yandex.Disk downloads the file from the new address. This is the default value.

  • “true” — If a redirect is detected, Yandex.Disk doesn't follow it or download anything.

*  Required

Response format

Downloading a file may require some time. If the download operation started, the API responds with the 202 Accepted code and a link to the operation status (in the response body, in the Link object). If the request caused an error, the relevant response code is returned, and the response body contains the error description.

Your application must track the status of the operation by using the received link:

  • The success status means the file was downloaded successfully.
  • The failed status means the file could not be downloaded. In this case, your application can try to download the file itself and then upload it using the Upload a file to Disk request.

Sample response:

{  "href": "https://cloud-api.yandex.net/v1/disk/operations?id=33ca7d03ab21ct41b4a40182e78d828a3f8b72cdb5f4c0e94cc4b1449a63a2fe",  "method": "GET",  "templated": false}
Response elements
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. Before sending a request to this address, put the desired parameter values in place of the values in curly brackets.
  • “false” — The URL can be requested without changes.