Actions with public files and folders
Alert
The meta information about the requested resource is unavailable if the owner of the link to the file or folder has disabled downloads.
Resources published by other users can be downloaded or copied to the Downloads folder. You can also request their meta information.
Each request to other users' published resources must contain the public key that Yandex Disk returns when publishing the file. You don't have to specify the OAuth token (or the Authorization
header) in such requests.
Meta information of public resources
If you know the key or public link to the resource, you can request meta information of this resource (the file properties or the folder properties and contents).
Request format
Use the GET method to send a request for meta information.
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=<preview crop flag>]
& [offset=<offset from the top of the list>]
- public_key*
-
The key of a published resource or a public link to a resource.
The parameter value should be encoded in URL format. - path
-
Relative path to the resource in the public folder. By specifying the key of the published folder in the
public_key
parameter, you can request meta information for any resource in the folder. For example, to receive the properties of the/foo
folder nested in the published folder, pass thepath=%2Ffoo
parameter.The path in the parameter value should be encoded in URL format.
- sort
-
The attribute by which the list of resources should be sorted in the folder. The following properties of the Resource object can be used as a value:
name
: resource name.path
: path to the resource on Yandex Disk.created
: date the resource was created.modified
: date the resource was modified.size
: file size.
To sort in reverse order, add a hyphen to the parameter value. For example:
sort=-name
. - 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 required size of the reduced image (file preview). Its link should be returned in the
preview
key.
You can specify the exact preview dimensions or the length of one side. The resulting image can be cropped to a square using thepreview_crop
parameter.Possible values-
Predefined length of the longest side.
The image is reduced to the specified size along its larger dimension while preserving the aspect ratio of the original image. For example, for the "S" size and a 120×200 image, a 90×150 preview is generated. For a 300×100 image, the preview is 150×50.
Supported values:
-
"S"
: 150 pixels.
-"M"
: 300 pixels.
-"L"
: 500 pixels.
-"XL"
: 800 pixels.
-"XXL"
: 1024 pixels.
-"XXXL"
: 1280 pixels. -
Exact width (for example,
"120"
or"120x"
) or exact height (for example,"x145"
).The image is reduced to the specified width or height while preserving the aspect ratio of the original image.
If the
preview_crop
parameter is passed, a square with the specified side length is cropped out of the center of the reduced image. -
Exact size (in the
<width>x<height>
format, for example,"120x240"
).The image is reduced to the smallest of the specified dimensions while preserving the aspect ratio of the original image.
If the
preview_crop
is passed, a section of maximum size with the specified aspect ratio (in the example: 1 to 2) is cropped out of the center of the original image. Then the cropped section is scaled to the specified dimensions.
-
- preview_crop
-
This parameter crops the preview to the size specified in the
preview_size
parameter.
Supported values:
false
: the parameter is ignored (default value).true
: the preview is cropped as follows:
- If only the width or height is passed, the image is reduced to this size with the same aspect ratio. Then a square with the specified side length is cropped out of the center of the reduced image.
- If the exact size is passed (for example, "120x240"), a section of maximum size with the specified aspect ratio is cropped out of the center of the source image. Then the cropped section is scaled to the specified dimensions.
- If only the width or height is passed, the image is reduced to this size with the same aspect ratio. Then a square with the specified side length is cropped out of the center of the reduced image.
- offset
-
The number of resources starting from the top of the list that should be skipped in the response (for example, for paginated output).
Let's say the
/foo
folder contains three files. If you request the folder meta information with the offset parameter set to 1 (offset=1
), the Yandex Disk API returns only the second and third file information.
* Required parameter.
Response format
If the request is processed without errors, the API returns the 200 OK
code and meta information about the requested resource within the Resource object in the response body.
If the request caused an error, the relevant response code is returned, and the response body contains an error description.
For non-empty folders, the response includes a ResourceList object (under the _embedded
name). Each resource in the folder is an element of the items
array. Regardless of the requested sort, resources in the array are ordered by type: nested folders go first, followed by folder files.
The published folder's meta information should include all paths relative to the folder.
Here's an example response for the published /foo
folder that contains the /bar
folder and the photo.png
file:
{
"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 |
|
Key of a published resource. It's included in the response only if the specified file or folder is published. |
|
Link to a published resource. It's included in the response only if the specified file or folder is published. |
|
The resources in the folder (contains the ResourceList object). It's included in the response only when the folder meta information is requested. |
|
Link to a preview image of the file. It's included in the response only for supported image formats. The preview can only be requested with the OAuth token of a user who has access to the file. |
|
Resource name. |
|
The object contains all attributes specified by the Adding resource meta information request. Contains only keys of the |
|
The date and time when the resource was created, in ISO 8601 format. |
|
The date and time when the resource was modified, in ISO 8601 format. |
|
Full path to the resource on Yandex Disk. The meta information of the published folder indicates paths relative to the folder. For published files, the key value is always "/". For a resource in Trash, this attribute may have a unique ID added to it (for example, |
|
Path to the resource before it was moved to Trash. Only included in the response to a meta information request related to a resource in Trash. |
|
MD5 hash of the file. |
|
Resource type:
|
|
The MIME type of the file. |
|
File size. |
Element |
Description |
|
The field by which the list is sorted. |
|
The key of the published folder that contains resources from this list. It's included in the response only if a public folder's meta information is requested. |
|
Array of resources (Resource) located in the folder. Regardless of the requested sort, resources in the array are ordered by type: nested folders go first, followed by folder files. |
|
The maximum number of items in the |
|
The offset from the first resource in the folder to the top of the list. |
|
The path to the folder whose contents are described in the For a public folder, the attribute value is always "/". |
|
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 its key or the 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 a request for downloading a file.
https://cloud-api.yandex.net/v1/disk/public/resources/download
? public_key=<key of a published resource>
& [path=<resource path>]
- public_key*
-
The key of a public file or folder.
The parameter value should be encoded in URL format. - path
-
The path to the file in 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 encoded in URL format.
* Required parameter.
Response format
If the request is processed without errors, the API returns the 200 OK
code. The response body includes a Link object with the generated URL for downloading the file.
If the request caused an error, the relevant response code is returned, and the response body contains an error description.
Sample response:
{
"href": "https://downloader.dst.yandex.ru/disk/...",
"method": "GET",
"templated": false
}
Element |
Description |
|
URL. It may be a URL template. See the |
|
The HTTP method for requesting the URL from the |
|
Indicates a URL template according to RFC 6570. Possible values:
|
Use the GET method to download the 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 is processed without errors, the API returns the 200 OK
code.
Saving a public file to the Downloads folder
A file published on Yandex Disk can be copied to the Dowloads folder on the user's Yandex Disk. To do this, you need to know the key or public link to the file. If you know the public folder key, you can also copy individual files from it.
Request format
Use the POST method to send a request for saving a file.
https://cloud-api.yandex.net/v1/disk/public/resources/save-to-disk
? public_key=<key of a published resource>
& [path=<resource path>]
& [name=<name of the saved file>]
- public_key*
-
The key of the resource to save.
The parameter value should be encoded in URL format. - path
-
The path in 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 encoded in URL format.
- name
-
The name for saving the file in the Downloads folder.
* Required parameter.
Response format
Saving a public file to the user's Disk may take some time. Depending on the operation status, the Yandex Disk server returns one of these responses:
If the request is processed without errors, the API returns the 201 Created
code. The Link object in the response body contains the link to the saved file.
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 |
|
URL. It may be a URL template. See the |
|
The HTTP method for requesting the URL from the |
|
Indicates a URL template according to RFC 6570. Possible values:
|
If saving has started but not completed yet, Yandex Disk returns the 202 Accepted
code.
Apps must track the status of requested operations. Yandex Disk returns a link to the status of the requested operation within 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 |
|
URL. It may be a URL template. See the |
|
The HTTP method for requesting the URL from the |
|
Indicates a URL template according to RFC 6570. Possible values:
|
If the request caused an error, the relevant response code is returned, and the response body contains an error description.
The key of a published resource or a public link to a resource.
The parameter value should be encoded in URL format.
Relative path to the resource in the public folder. By specifying the key of the published folder in the public_key
parameter, you can request meta information for any resource in the folder. For example, to receive the properties of the /foo
folder nested in the published folder, pass the path=%2Ffoo
parameter.
The path in the parameter value should be encoded in URL format.
The attribute by which the list of resources should be sorted in the folder. The following properties of the Resource object can be used as a value:
name
: resource name.path
: path to the resource on Yandex Disk.created
: date the resource was created.modified
: date the resource was modified.size
: file size.
To sort in reverse order, add a hyphen to the parameter value. For example: sort=-name
.
The number of resources in the folder that should be described in the response (for example, for paginated output).
The default value is 20.
The required size of the reduced image (file preview). Its link should be returned in the preview
key.
You can specify the exact preview dimensions or the length of one side. The resulting image can be cropped to a square using the preview_crop
parameter.
-
Predefined length of the longest side.
The image is reduced to the specified size along its larger dimension while preserving the aspect ratio of the original image. For example, for the "S" size and a 120×200 image, a 90×150 preview is generated. For a 300×100 image, the preview is 150×50.
Supported values:
-
"S"
: 150 pixels.
-"M"
: 300 pixels.
-"L"
: 500 pixels.
-"XL"
: 800 pixels.
-"XXL"
: 1024 pixels.
-"XXXL"
: 1280 pixels. -
Exact width (for example,
"120"
or"120x"
) or exact height (for example,"x145"
).The image is reduced to the specified width or height while preserving the aspect ratio of the original image.
If the
preview_crop
parameter is passed, a square with the specified side length is cropped out of the center of the reduced image. -
Exact size (in the
<width>x<height>
format, for example,"120x240"
).The image is reduced to the smallest of the specified dimensions while preserving the aspect ratio of the original image.
If the
preview_crop
is passed, a section of maximum size with the specified aspect ratio (in the example: 1 to 2) is cropped out of the center of the original image. Then the cropped section is scaled to the specified dimensions.
This parameter crops the preview to the size specified in the preview_size
parameter.
Supported values:
false
: the parameter is ignored (default value).true
: the preview is cropped as follows:
- If only the width or height is passed, the image is reduced to this size with the same aspect ratio. Then a square with the specified side length is cropped out of the center of the reduced image.
- If the exact size is passed (for example, "120x240"), a section of maximum size with the specified aspect ratio is cropped out of the center of the source image. Then the cropped section is scaled to the specified dimensions.
- If only the width or height is passed, the image is reduced to this size with the same aspect ratio. Then a square with the specified side length is cropped out of the center of the reduced image.
The number of resources starting from the top of the list that should be skipped in the response (for example, for paginated output).
Let's say the /foo
folder contains three files. If you request the folder meta information with the offset parameter set to 1 (offset=1
), the Yandex Disk API returns only the second and third file information.
The key of a public file or folder.
The parameter value should be encoded in URL format.
The path to the file in the public folder. Specify it if thepublic_key
parameter contains the key of the public folder where the file is located.
The path in the parameter value should be encoded in URL format.
The key of the resource to save.
The parameter value should be encoded in URL format.
The path in the public folder. Specify it if thepublic_key
parameter contains the key of the public folder where the file is located.
The path in the parameter value should be encoded in URL format.
The name for saving the file in the Downloads folder.
Required parameter.