Answer the question
In order to leave comments, you need to log in
How to programmatically download a file from Yandex.Disk?
Good afternoon.
There are files on the Yandex disk with public links, for example, https://disk.yandex.ru/public/?hash=Zn9rQik51OUzcW...
How to programmatically download a file, for example, in php?
Answer the question
In order to leave comments, you need to log in
Here is an example implementation in php:
function get_stat( $url, $headers )
{
$handle = curl_init();
curl_setopt( $handle, CURLOPT_URL, $url );
curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $handle );
$code = curl_getinfo( $handle, CURLINFO_HTTP_CODE );
return array( "code" => $code, "response" => $response );
}
$url_yandex_disk = "https://yadi.sk/i/byMUqoSLiw3Ki";
$result = get_stat( "https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key=" . urlencode( $url_yandex_disk ), array() );
if( $result["code"] == 200 )
{
$result["response"] = json_decode( $result["response"], true );
echo '<a href="' . $result["response"]["href"] . '">Скачать</a>';
}
else
{
echo "error";
}
$url_yandex_disk = $_GET["ya_url"];
$result = get_stat( "https://cloud-api.yandex.net:443/v1/disk/public/resources/download?public_key=" . urlencode( $url_yandex_disk ), array() );
if( $result["code"] == 200 )
{
$result["response"] = json_decode( $result["response"], true );
header( "Location: " . $result["response"]["href"], true, 302 );
exit( 0 );
}
import requests
import pprint
import urllib.parse
targetUrl = "https://yadi.sk/i/03bE933n3PqpG2"
url = "https://cloud-api.yandex.net/v1/disk/public/resources?public_key=" + urllib.parse.quote(targetUrl, safe="")
responseData = requests.get(url)
if responseData.headers["content-type"] in ["application/json; charset=utf-8", "application/json"]:
print(pprint.pformat(responseData.json()))
else:
print(responseData)
did you solve the problem?
I have a public link to the file, I need to somehow download it.
https://yadi.sk/d/Rzdip...
I can't find where to start
according to https://tech.yandex.ru/disk/api/reference/public-d... I need a publick_key, but where can I get it?
Good day to all, but tell me how to make it so that it would be like on the site https://getfile.dokpub.com/yandex/
When after https://getfile.dokpub.com/yandex/get/Yandex link
Gives a direct link to the file .
Just do it on your site, for example, so that I enter http://my.say/get/Yandex link
And everything worked OK!
Tell me please(
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question