E
E
Evgeny Kylin2016-10-28 17:28:23
PHP
Evgeny Kylin, 2016-10-28 17:28:23

How to copy a file to Yandex Disk PHP REST API?

$from = '/X/photo/123.jpg';
$path = '/X/111/123.jpg';
$token =  'токен';

$curl2 = curl_init();
    curl_setopt($curl2, CURLOPT_HTTPHEADER, array('Authorization: OAuth '.$token));
    curl_setopt($curl2, CURLOPT_URL, 'https://cloud-api.yandex.net/v1/disk/resources/copy?from='.$from.'&path='.$path);
    curl_setopt($curl2, CURLOPT_POST, true);
    curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($curl2);
    curl_close($curl2);

With such a request, 400 Bad Request
is returned Without curl_setopt($curl2, CURLOPT_POST, true);writing: "the method is not supported."
Everything goes through the Yandex.Disk API test site normally.
In the documentation they write
The copy request should be sent using the POST method.
but somehow it doesn't work for me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Kulik, 2016-10-28
@sanyakulik88

So tried https://tech.yandex.ru/disk/api/reference/create-f... ?

E
Evgeniy Kylin, 2016-10-28
@palkan_karabov

As always, I just wrote a post and immediately solved the problem!
just had to add:
curl_setopt($curl, CURLOPT_POSTFIELDS, false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question