Actions with public files and folders
Resources published by other users can be downloaded or copied to the “Downloads” folder. You can also request their metainformation.
In each request to other people's published resources, you must specify the public key that Yandex.Disk returns when publishing the file. You do not need to specify the OAuth token (or the Authorization
header) in such requests.
Metainformation about a public resource
If you know the key for a public resource or the public link to it, you can request metainformation about this resource (the file properties or properties of the folder contents).
Request format
Use the GET method to send a request for metainformation.
https://cloud-api.yandex.net/v1/disk/public/resources
? public_key=<key of a published resource>
& [path=<resource path>]
& [sort=<sorting attribute>]
& [limit=<maximum number of returned resources>]
& [preview_size=<preview size>]
& [preview_crop=<whether to crop the preview>]
& [offset=<offset from the top of the list>]
public_key * | Key to a public resource, or the public link to a resource. The parameter value should be URL-encoded. |
path | Relative path to a resource in a public folder. By specifying the key of the published folder in The path in the parameter value should be URL-encoded. |
sort | The attribute used to sort the list of resources in the folder. The following properties of the Resource object can be used as a value:
To sort in reverse order, add a hyphen to the parameter value, for example: |
limit | The number of resources in the folder that should be described in the response (for example, for paginated output). The default value is 20. |
preview_size | The desired size of the thumbnail (preview) file. The thumbnail link is returned in the You can define the exact size of the preview, or the length of one of the sides. The resulting image can be cropped to a square using the
Possible values |
preview_crop | This parameter crops the preview to the size specified in the Acceptable values:
|
offset | The number of resources from the top of the list that should be skipped in the response (used for paginated output). Let's say the /foo folder contains three files. For a folder metainformation request with the |
public_key * | Key to a public resource, or the public link to a resource. The parameter value should be URL-encoded. |
path | Relative path to a resource in a public folder. By specifying the key of the published folder in The path in the parameter value should be URL-encoded. |
sort | The attribute used to sort the list of resources in the folder. The following properties of the Resource object can be used as a value:
To sort in reverse order, add a hyphen to the parameter value, for example: |
limit | The number of resources in the folder that should be described in the response (for example, for paginated output). The default value is 20. |
preview_size | The desired size of the thumbnail (preview) file. The thumbnail link is returned in the You can define the exact size of the preview, or the length of one of the sides. The resulting image can be cropped to a square using the
Possible values |
preview_crop | This parameter crops the preview to the size specified in the Acceptable values:
|
offset | The number of resources from the top of the list that should be skipped in the response (used for paginated output). Let's say the /foo folder contains three files. For a folder metainformation request with the |
* Required
Response format
If the request was processed without errors, the Yandex.Disk API responds with the code 200 OK
and returns the metainformation about the requested resource in the response body, in the Resource object. If the request caused an error, the relevant response code is returned, and the response body contains the error description.
For non-empty folders, the response includes the ResourceList object (under the _embedded
name). Each resource in the folder is an element of the items
array. Regardless of the requested sorting, resources in the array are ordered by type: first all the subfolders are listed, then all the files.
In the metainformation for a published folder, all paths are relative to the folder itself.
An example response is shown for the published folder /foo, which contains the folder /bar and the file photo.png:
{ "public_key": "aSsmHLoeyBlJw8Eu1jlmzuU+ZaLkjPkgcvmokRUCIo8=", "_embedded": { "sort": "", "public_key": "kLsmHRoeyBlJf8Eu1jlmzuU+ZaLkjPkgcvmokRUCIo8=", "items": [ { "public_key": "HQsmHLoeyBlJf8Eu1jlmzuU+ZaLkjPkgcvmokRUCIo8=", "name": "bar-1", "created": "2014-05-22T14:30:16+04:00", "modified": "2014-05-22T14:30:16+04:00", "path": "/bar-1", "type": "dir" }, { "public_key": "HQsmHLoeyBlJf8Eu1jlmzuU+ZaLkjPkgcvmokRUCIo8=", "preview": "https://downloader.disk.yandex.ru/preview/...", "name": "photo.png", "created": "2014-08-08T12:36:23+04:00", "modified": "2014-08-08T12:36:23+04:00", "path": "/photo.png", "md5": "dc27c182eda45002d641b68937029301", "type": "file", "mime_type": "image/png", "size": 29293 } ], "limit": 20, "offset": 0, "path": "/", "total": 4 }, "name": "foo", "created": "2014-05-22T14:30:09+04:00", "public_url": "https://yadi.sk/d/AaaBbb1122Ccc", "modified": "2014-05-22T14:30:09+04:00", "path": "/", "type": "dir"}
Element | Description |
---|---|
public_key | Key of a published resource. It is included in the response only if the specified file or folder is published. |
public_url | Link to a published resource. It is included in the response only if the specified file or folder is published. |
_embedded | The resources located in the folder (contains the ResourceList object). It is included in the response only when folder metainformation is requested. |
preview | Link to a small image (preview) for the file. It is included in the response only for files that support graphic formats. The preview can only be requested using the OAuth token of a user who has access to the file itself. |
name | Resource name. |
custom_properties | An object with all attributes set with the Adding metainformation for a resource request. Contains only keys in the name:value format (cannot contain objects or arrays). |
created | The date and time when the resource was created, in ISO 8601 format. |
modified | The date and time when the resource was modified, in ISO 8601 format. |
path | Full path to the resource on Yandex.Disk. In metainformation for a published folder, paths are relative to the folder itself. For published files, the value of the key is always "/". For a resource located in the Trash, this attribute may have a unique ID appended to it (for example, |
origin_path | Path to the resource before it was moved to the Trash. Included in the response only for a request for metainformation about a resource in the Trash. |
md5 | MD5 hash of the file. |
type | Resource type:
|
mime_type | The MIME type of the file. |
size | File size. |
Element | Description |
sort | The field used for sorting the list. |
public_key | The key of a published folder that contains resources from this list. It is included in the response only if metainformation about a public folder is requested. |
items | Array of resources (Resource) contained in the folder. Regardless of the requested sorting, resources in the array are ordered by type: first all the subfolders are listed, then all the files. |
limit | The maximum number of items in the |
offset | How much to offset the beginning of the list from the first resource in the folder. |
path | The path to the folder whose contents are described in this For a public folder, the value of the attribute is always "/". |
total | The total number of resources in the folder. |
Element | Description |
---|---|
public_key | Key of a published resource. It is included in the response only if the specified file or folder is published. |
public_url | Link to a published resource. It is included in the response only if the specified file or folder is published. |
_embedded | The resources located in the folder (contains the ResourceList object). It is included in the response only when folder metainformation is requested. |
preview | Link to a small image (preview) for the file. It is included in the response only for files that support graphic formats. The preview can only be requested using the OAuth token of a user who has access to the file itself. |
name | Resource name. |
custom_properties | An object with all attributes set with the Adding metainformation for a resource request. Contains only keys in the name:value format (cannot contain objects or arrays). |
created | The date and time when the resource was created, in ISO 8601 format. |
modified | The date and time when the resource was modified, in ISO 8601 format. |
path | Full path to the resource on Yandex.Disk. In metainformation for a published folder, paths are relative to the folder itself. For published files, the value of the key is always "/". For a resource located in the Trash, this attribute may have a unique ID appended to it (for example, |
origin_path | Path to the resource before it was moved to the Trash. Included in the response only for a request for metainformation about a resource in the Trash. |
md5 | MD5 hash of the file. |
type | Resource type:
|
mime_type | The MIME type of the file. |
size | File size. |
Element | Description |
sort | The field used for sorting the list. |
public_key | The key of a published folder that contains resources from this list. It is included in the response only if metainformation about a public folder is requested. |
items | Array of resources (Resource) contained in the folder. Regardless of the requested sorting, resources in the array are ordered by type: first all the subfolders are listed, then all the files. |
limit | The maximum number of items in the |
offset | How much to offset the beginning of the list from the first resource in the folder. |
path | The path to the folder whose contents are described in this For a public folder, the value of the attribute is always "/". |
total | The total number of resources in the folder. |
Downloading a public file or folder
You can download a resource published on Yandex.Disk if you know the key or public link to it. You can also use this operation to download individual files from public folders.
Request format
Use the GET method to send the request to download a file.
https://cloud-api.yandex.net/v1/disk/resources/download
? public_key=<key of a published resource>
& [path=<resource path>]
public_key * | The public file or folder key. The parameter value should be URL-encoded. |
path | The path to the file within the public folder. Specify it if the public_key parameter contains the key of the public folder where the file is located. The path in the parameter value should be URL-encoded. |
public_key * | The public file or folder key. The parameter value should be URL-encoded. |
path | The path to the file within the public folder. Specify it if the public_key parameter contains the key of the public folder where the file is located. The path in the parameter value should be URL-encoded. |
* 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 returns the generated URL for downloading the file.
If the request caused an error, a relevant response code is returned, with the response body featuring the error description.
Sample response:
{ "href": "https://downloader.dst.yandex.ru/disk/...", "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:
|
Use the GET method to download a file:
https://downloader.dst.yandex.ru/disk/53139aa0et584d3bac7eeab405d3574b/535320b4/YyjTJtEHob8R5WbpojJbiiUuU2HC_2JSTU0gW9qE0NHGW2uncmBjM_-IXun3Msyij96FTHQGSX-fDL-XwokDvA%3D%3D?uid=202727674&filename=photo.png&disposition=attachment&hash=&limit=0&content_type=application%2Fx-www-form-urlencoded&fsize=34524&hid=93528043563b8r55723a253f4730290a&media_type=document
If the request was processed without errors, the API responds with a file with the code 200 OK
.
Saving a public file in "Downloads"
A file published on Yandex.Disk can be copied to the “Dowloads” folder on the user's Disk. To do this, you need to know the key to the file or the public link to it. If you know the public folder key, you can also copy individual files from it.
Request format
Use the POST method to send the request to save a file.
https://cloud-api.yandex.net/v1/disk/resources/download
? public_key=<key of a published resource>
& [path=<resource path>]
& [name=<name of the saved file>]
public_key * | Key for a stored resource. The parameter value should be URL-encoded. |
path | The path within the public folder. Specify it if the The path in the parameter value should be URL-encoded. |
name | The name for saving the file in the “Downloads” folder. |
public_key * | Key for a stored resource. The parameter value should be URL-encoded. |
path | The path within the public folder. Specify it if the The path in the parameter value should be URL-encoded. |
name | The name for saving the file in the “Downloads” folder. |
* Required
Response format
Saving a public file to a user's Disk may take some time. Depending on the operation status, the Yandex.Disk server returns one of these responses:
If the request was completed without errors by the time of the response, the API responds with the code 201 Created
and returns the link to the saved file in the response body (in the Link object).
Sample response:
{
"href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2F%D0%97%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B8%photo.png",
"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:
|
If the save operation was started but has not yet finished, Yandex.Disk responds with the code 202 Accepted
.
Applications must track the status of requested operations. Yandex.Disk returns the link to the status of the operation launched by the request. The link is included in the Link object in the response body.
Sample response:
{ "href": "https://cloud-api.yandex.net/v1/disk/operations/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:
|