I have a PHP script that POSTs to Mixcloud and receiving an error I have not been able to resolve.
This is using PHP 7.3.6 and curl as I've seen in other posts as example.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.mixcloud.com/upload/?access_token=$mixcloud");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60 * 10);
curl_setopt($ch, CURLOPT_NOPROGRESS, true);
$server_output = curl_exec($ch);
curl_close ($ch);
// load json response into array
$res = json_decode($server_output, true);
echo print_r( $post, true );
echo print_r($res, true);
The upload fails with the following post that was sent:
Array
(
[mp3] => @/var/share_ro/fullshow/surface.mp3
[name] => Upload title
[description] => Upload description
[picture] => @/var/share_ro/fullshow/avatar.png
[tags-0-tag] => Tag1
[tags-1-tag] => Tag2
[tags-2-tag] => Tag3
[tags-3-tag] => Tag4
[tags-4-tag] => Tag5
)
and response:
Array
(
[details] => Array
(
[mp3] => Array
(
[0] => This field is required.
)
)
[error] => Array
(
[message] =>
[type] => PostValidationError
)
)
However, the full path to the file does exist and I have tried with and without the leading @
on the file name:
$ ls -lah /var/share_ro/fullshow/surface.mp3
-rw-r--r-- 1 user mp3 79M Jun 11 16:08 /var/share_ro/fullshow/surface.mp3
Can someone see what it is I'm doing wrong?