I am trying to upload a file (input type and named "upload") through the echonest api but am struggling to get the curl upload working.
http://developer.echonest.com/docs/v4/track.html#upload
Can anybody point me into the right direction to get the data-binary and header: application/octet-stream POST method working. This A HTTP POST request with Content-Type "application/octet-stream", with the local file as the body of the request, and the parameters in the URL.
the curl php:
$localfile = $_FILES['upload']['name'];
$fp = fopen($localfile, 'r');
$post = array('$localfile'=>'@$localfile','api_key'=>'xx','filetype'=>'mp3');
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); // --data-binary
curl_setopt($ch, CURLOPT_URL, 'http://developer.echonest.com/api/v4/track/upload');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, 'Content-type: application/octet-stream');
$response = curl_exec($ch);
$result = json_decode($response,true);
$id = $result['response']['track']['id'];
curl_close($ch);
fclose($fp);
echo $id;