cheechm Posted January 30, 2013 Share Posted January 30, 2013 Little help please!! $parameters['audio_clip[uploaded_data]'] = "@http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . "upload/" . $_FILES['test_file']['name'] .";type=". $_FILES['test_file']['type']; $parameters['audio_clip[uuid]'] = gen_uuid(); $parameters['audio_clip[title]'] = "Remote Upload Test"; $parameters['audio_clip[recorded_at]'] = ""; $parameters['audio_clip[tag_list]'] = "tag, podcast, test"; $parameters['audio_clip[category_id]'] = 60; $options = array(); $options['RequestContentType'] = "multipart/form-data"; $options['RequestBody'] = ''; $options['return_auth'] = 1; $auth = $client->CallAPI($url, $method, $parameters, $options, $response); $headers = array( "POST ".$auth['RequestURI']." HTTP/1.0", "Authorization: " . $auth['Headers']['Authorization'], "Accept: */*", "Host: " . $auth['Headers']['Host'], "Content-Type: multipart/form-data", "Content-Length" . $auth['Headers']['Content-Length'], "User-Agent: " . $auth['Headers']['User-Agent'] ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $exec = curl_exec($ch); curl_close($ch); echo "<pre>Output: "; print_r($exec); echo "</pre>"; Trying to upload a file via the API to audioboo.fm . The relevant documentation is here: https://github.com/Audioboo/api/blob/master/sections/audio_clips.md The reply I get from the server is raw attachment invalid/blank. Not sure what I'm doing wrong? I can manage simple PUT/GET requests and I know I'm authenticated properly, however I'm having trouble sending a file. (It is an MP3). Cheers Quote Link to comment https://forums.phpfreaks.com/topic/273846-posting-a-file-using-curl/ Share on other sites More sharing options...
requinix Posted January 30, 2013 Share Posted January 30, 2013 cURL might want a path to an actual file on the filesystem. Is the Content-Length correct? It'll be the size of the file plus the size of all the form fields, plus a lot of extra overhead because it's multipart/form-data. Try omitting it. Quote Link to comment https://forums.phpfreaks.com/topic/273846-posting-a-file-using-curl/#findComment-1409239 Share on other sites More sharing options...
cheechm Posted January 30, 2013 Author Share Posted January 30, 2013 Perfect. Thanks requinix. Thread solved! Quote Link to comment https://forums.phpfreaks.com/topic/273846-posting-a-file-using-curl/#findComment-1409244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.