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 monitor the download progress. If an error occurs, Yandex Disk doesn't try to download the file again.

If the file fails to download directly to Yandex Disk, you can try downloading it manually and uploading it to Yandex Disk using the Uploading a file to Yandex Diskrequest.

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 being downloaded>
 & path=<path to the folder the file should be downloaded to>
 & [fields=<properties to include in the response>]
 & [disable_redirects=<redirect disable flag>]
url*

The link to the file to download. For example, http%3A%2F%2Fexample.com%2Fphoto.png. The maximum file name length is 255 characters. The maximum path length is 32760 characters.

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

path*

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

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

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.

disable_redirects

This parameter disables redirects for the address specified in the url parameter.

Supported 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 parameter.

Response format

Downloading a file may take some time. If the download started, the API returns the 202 Accepted code. The response body contains the link to the operation status within the Link object.

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

Your app must track the operation status using the link:

  • The success status means that the file was downloaded successfully.
  • The failed status means that the file couldn't be downloaded. In this case, your app can try downloading the file and uploading it to Yandex Disk using the Uploading a file to Yandex Disk request.

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 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.

The link to the file to download. For example, http%3A%2F%2Fexample.com%2Fphoto.png. The maximum file name length is 255 characters. The maximum path length is 32760 characters.

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

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

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

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.

This parameter disables redirects for the address specified in the url parameter.

Supported 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 parameter.