Publishing files and folders
Files and folders that are uploaded to Yandex Disk can be published by generating a link that makes them accessible to people other than the Yandex Disk owner.
Published files and folders can be reverted to private status, and the generated public links to the file will stop working.
Use the PROPPATCH
method to set and change the "public" status. To publish a file or folder, assign any non-empty value to the public_url
property in the urn:yandex:disk:meta
namespace.
Example of publishing a folder
Publishing the /public_folder/ folder located in the root directory of the user's Disk.
PROPPATCH /public_folder/ HTTP/1.1 User-Agent: my_application/0.0.1 Host: webdav.yandex.ru Authorization: OAuth 0c4182a7c2cf4521964a72ff57a34a07 Content-Length: 158 <propertyupdate xmlns="DAV:"> <set> <prop> <public_url xmlns="urn:yandex:disk:meta">true</public_url> </prop> </set> </propertyupdate>
If the folder was published successfully, the server responds with:
HTTP/1.1 207 Multi-Status Content-Type: application/xml; charset="utf-8" Content-Length: 390 <?xml version="1.0" encoding="utf-8"?> <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/public_folder/</d:href> <d:propstat> <d:status>HTTP/1.1 200 OK</d:status> <d:prop> <public_url xmlns="urn:yandex:disk:meta"> http://yadi.sk/d/FTb3fLiI49Xt0 </public_url> </d:prop> </d:propstat> </d:response> </d:multistatus>
The link to the published folder is returned in the value of the
public_url
element. If you attempt to publish a folder that is already published, Yandex Disk returns the link that was generated during the first publication.
Example of publishing a file
Publishing the readme.txt file located in the /public_folder/ directory on the user's Disk.
PROPPATCH /public_folder/readme.txt HTTP/1.1 User-Agent: my_application/0.0.1 Host: webdav.yandex.ru Authorization: OAuth 0c4182a7c2cf4521964a72ff57a34a07 Content-Length: 158 <propertyupdate xmlns="DAV:"> <set> <prop> <public_url xmlns="urn:yandex:disk:meta">true</public_url> </prop> </set> </propertyupdate>
If the file was published successfully, the server responds with:
HTTP/1.1 207 Multi-Status Content-Type: application/xml; charset="utf-8" Content-Length: 400 <?xml version="1.0" encoding="utf-8"?> <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/public_folder/readme.txt</d:href> <d:propstat> <d:status>HTTP/1.1 200 OK</d:status> <d:prop> <public_url xmlns="urn:yandex:disk:meta"> http://yadi.sk/d/UDh3fLiI49Xt0 </public_url> </d:prop> </d:propstat> </d:response> </d:multistatus>
The link to the published file is returned in the value of the
public_url
element. If you attempt to publish a file that is already published, Yandex Disk returns the link that was generated during the first publication.
Example of unpublishing a published file
The readme.txt file in the /public_folder/ catalog on the user's Disk is switched to “private” status - the
public_url
property is deleted.
PROPPATCH /public_folder/readme.txt HTTP/1.1 User-Agent: my_application/0.0.1 Host: webdav.yandex.ru Authorization: OAuth 0c4182a7c2cf4521964a72ff57a34a07 Content-Length: 149 <propertyupdate xmlns="DAV:"> <remove> <prop> <public_url xmlns="urn:yandex:disk:meta" /> </prop> </remove> </propertyupdate>
In the response, Yandex Disk confirms that the property value is now empty:
HTTP/1.1 207 Multi-Status Content-Type: application/xml; charset="utf-8" Content-Length: 336 <?xml version="1.0" encoding="utf-8"?> <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/public_folder/readme.txt</d:href> <d:propstat> <d:status>HTTP/1.1 200 OK</d:status> <d:prop> <public_url xmlns="urn:yandex:disk:meta" /> </d:prop> </d:propstat> </d:response> </d:multistatus>
If you attempt to unpublish a file that was not published, the server response is the same - Yandex Disk informs you that the property value is empty.
Example of checking public status
Checking whether the /public_folder/ directory is public: using the
PROPFIND
method, we request the value of thepublic_url
property.
PROPFIND /public_folder/ HTTP/1.1 User-Agent: my_application/0.0.1 Host: webdav.yandex.ru Authorization: OAuth 0c4182a7c2cf4521964a72ff57a34a07 Depth: 0 Content-Length: 105 <propfind xmlns="DAV:"> <prop> <public_url xmlns="urn:yandex:disk:meta"/> </prop> </propfind>
If the folder is published, the server returns a public link in the property value:
HTTP/1.1 207 Multi-Status Content-Type: application/xml; charset="utf-8" Content-Length: 390 <?xml version="1.0" encoding="utf-8"?> <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/public_folder/</d:href> <d:propstat> <d:status>HTTP/1.1 200 OK</d:status> <d:prop> <public_url xmlns="urn:yandex:disk:meta"> http://yadi.sk/d/FTb3fLiI49Xt0 </public_url> </d:prop> </d:propstat> </d:response> </d:multistatus>
If the folder is not published, the server reports that the property value is empty:
HTTP/1.1 207 Multi-Status Content-Type: application/xml; charset="utf-8" Content-Length: 340 <?xml version="1.0" encoding="utf-8"?> <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/public_folder/</d:href> <d:propstat> <d:status>HTTP/1.1 404 Object Not Found</d:status> <d:prop> <public_url xmlns="urn:yandex:disk:meta" /> </d:prop> </d:propstat> </d:response> </d:multistatus>