Uploading a file to Yandex.Disk

To upload a file to Yandex.Disk:

  1. Upload the file to the given address.

Upload URL request

When you have given the Yandex.Disk API the desired path to the uploaded file, you receive a URL for accessing the file uploader.

Request format

Use the GET method to send a request for an upload URL.

https://cloud-api.yandex.net/v1/disk/resources/upload
 ? path=<path for the file upload>
 & [overwrite=<overwriting flag>]
 & [fields=<properties to include in the response>]
Query parameters
path *

The path where you want to upload the file. For example, %2Fbar%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.

overwrite

Whether to overwrite the file. It is used if the file is uploaded to a folder that already contains a file with the same name.

Acceptable values:

  • false — Do not overwrite the file; cancel uploading (default value).

  • true — Delete the file with the same name and save the uploaded file.

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.

*  Required

Response format

If the request was processed without errors, the API responds with the code 200 OK. The Link object in the response body contains the URL generated for the file upload. If this URL is not requested within 30 minutes, it will stop working, and a new URL will have to be requested.

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

Sample response:

{  "href": "https://uploader1d.dst.yandex.net:443/upload-target/...",  "method": "PUT",  "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.

Uploading the file to the URL

The file should be sent using the PUT method to the upload URL, within 30 minutes of getting this URL (after 30 minutes, the link stops working and it will have to be requested again). The OAuth token isn't necessary for uploading to the storage.

Example of an upload URL:

https://uploader1d.dst.yandex.net:443/upload-target/20240424T101447.217.utd.52csloukwvq67nab1yc84a3xw-k1d.6625

Response format

If the request was processed without errors, the API responds with the code 201 Created.

Sample HTTP response:

HTTP/1.1 201 CreatedContent-Length: 0

Response codes when uploading a file

The API responds with the 201 Created code if the file was uploaded without errors.

Other HTTP response codes:

  • 202 Accepted — The file was received by the server but hasn't been transferred to the Yandex.Disk yet.

  • 412 Precondition Failed — Wrong range was passed in the Content-Range header when uploading the file.

  • 413 Payload Too Large — The file size exceeds 10 GB.

  • 500 Internal Server Error or 503 Service Unavailable — Server error. Try to repeat the upload.

  • 507 Insufficient Storage — There's not enough free space on the user's Disk for the uploaded file.