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>]
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: |
disable_redirects | Use this parameter to disable redirects for the address specified in the Acceptable values:
|
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: |
disable_redirects | Use this parameter to disable redirects for the address specified in the Acceptable values:
|
* 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}
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:
|