Uploading a file to Yandex Disk

To upload a file to Yandex Disk:

  1. Request an upload URL.
  2. Upload the file to the address.

Upload URL request

When you provide the Yandex Disk API with the upload path, you receive a URL to access 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=<overwrite flag>]
 & [fields=<properties to include in the response>]
path*

The path the file should be uploaded to. For example, %2Fbar%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.

overwrite

File overwrite flag. Used if the file is uploaded to a folder that already contains a file with the same name.

Supported values:

  • false: don't overwrite the file and cancel upload (default value).
  • true: delete the existing file with the same name and save the uploaded file.
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.

* Required parameter.

Response format

If the request is processed without errors, the API returns the 200 OK code. The Link object in the response body contains the URL generated to upload the file. If this URL isn't requested within 30 minutes, it stops working and you have to request a new URL.

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

Sample response:

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

Uploading a file to a URL

Send the file to the upload URL using the PUT method within 30 minutes of getting the URL (after 30 minutes, the link will expire and you'll have to request a new link). You don't need an OAuth token to upload files to the storage.

Sample upload URL:

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

Response format

If the request is processed without errors, the API returns the 201 Created code.

Sample HTTP response:

HTTP/1.1 201 Created
Content-Length: 0

Response codes when uploading a file

In the file is uploaded without errors, the API returns the 201 Created code.

Other HTTP response codes:

  • 202 Accepted — The file has been received by the server but hasn't been moved to 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 is larger than allowed. If you have a Yandex 360 subscription, you can upload files up to 50 GB in size. Otherwise, the file size is limited to 1 GB.

  • 500 Internal Server Error or 503 Service Unavailable — Server error. Try re-uploading the file.

  • 507 Insufficient Storage — There isn't enough available space on the user's Disk to upload the file.