Jump to content

Posting a file using cURL


cheechm

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/273846-posting-a-file-using-curl/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.