Uploading a file to Yandex.Disk
To upload a file to Yandex.Disk:
- Upload the file to the given address.
Upload URL request
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>]
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:
|
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: |
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:
|
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: |
* 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}
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:
|
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 theContent-Range
header when uploading the file.413 Payload Too Large
— The file size exceeds 10 GB.500 Internal Server Error
or503 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.