Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.