Publishing a file or folder

You can publish a file or folder stored on Yandex Disk by generating a link that gives other users access to them. Access to previously published resources can be revoked.

A published resource gets two new attributes:

  • public_key — The key of the published resource. Other apps can use this key to get the published resource's meta information.
  • public_url — The public link to the resource in the format https://yadi.sk/.... With the link, users can open the published folder or download the file.

When the owner restricts access to the resource, these attributes are removed.

Publishing a resource

Restricting access to a resource

Publishing a resource

A resource becomes accessible via a direct link. You can only publish a resource using the file owner's OAuth token.

Request format

Use the PUT method to send a publish request.

https://cloud-api.yandex.net/v1/disk/resources/publish
 ? path=<path to the resource being published>
path*

The path to the resource being published. For example, %2Fbar%2Fphoto.png.

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 and the published resource's meta information within the Link object in the response body.

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "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.

Restricting access to a resource

The resource loses the public_key and public_url attributes, and the public links to it stop working. You can only restrict access to a resource using the resource owner's OAuth token.

Request format

Use the PUT method to restrict access to a resource.

https://cloud-api.yandex.net/v1/disk/resources/unpublish
 ? path=<path to the resource being restricted>
path*

The path to the resource being restricted. For example, %2Fbar%2Fphoto.png.

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 and the restricted resource's meta information within the Link object in the response body.

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "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.