Publishing a file or folder

Files and folders on a user's Disk can be published by generating links that will allow them to be accessed by people other than the owner. Access to a previously published resource can be closed.

A published resource gets two new attributes:

  • public_key — The key of the published resource. Other applications can use this key to get metadata of the published resource.
  • public_url — The public link to the resource, in the format https://yadi.sk/.... Users who are given this link by the resource's owner can open the published folder or download a file.

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

Publishing a resource

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

Request format

Use the PUT method to send the publication request.

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

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

The path in the parameter value should be URL-encoded.

path *

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

The path in the parameter value should be URL-encoded.

* Required

Response format

If the request was handled without errors, the API responds with the 200 OK code and returns a link to metainformation about the published resource in the response body (in the Link object).

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "templated": false
}
Response elements
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. Before sending a request to this address, put the desired parameter values in place of the values in curly brackets.
  • “false” — The URL can be requested without changes.
Response elements
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. Before sending a request to this address, put the desired parameter values in place of the values in curly brackets.
  • “false” — The URL can be requested without changes.

Closing access to a resource

The resource loses the public_key and public_url attributes, and the public links to it stop working. To close access to the resource, you need the resource owner's OAuth token.

Request format

To close access to a resource, use the PUT method.

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

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

The path in the parameter value should be URL-encoded.

path *

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

The path in the parameter value should be URL-encoded.

* Required

Response format

If the request was handled without errors, the API responds with the 200 OK code and returns a link to metainformation about the closed resource in the response body (in the Link object).

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "templated": false
}
Response elements
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. Before sending a request to this address, put the desired parameter values in place of the values in curly brackets.
  • “false” — The URL can be requested without changes.
Response elements
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. Before sending a request to this address, put the desired parameter values in place of the values in curly brackets.
  • “false” — The URL can be requested without changes.