Send records files with DIALPLAN

Hello !

Today i’m trying to send my records files with the Dialplan.

I tried this : (but of course that return only a string)

exten => s,n,Set(foo=${CURL("${CDR(recordingfile)}")})

What can i use to send this data correctly ?

Any advices will help !


For one, you might want to trigger after the hangup so you can get the mixed, complete recording.
Second, it might be better to send this to an AGI script to do the curl. My example is PHP but it could be Perl, Python, whatever floats your boat.

exten => h,1,AGI(recordupload.php)
exten => h,n,Hangup()

Then, in /var/lib/asterisk/agi-bin/ create recordupload.php:

$agi = new AGI();
function curl_upload($recording) {
…your curl specific stuff…
sleep(5); //Delay a few seconds to make sure recording is finished and mixed
$datepath = date(“/Y/m/d/”);
$astspooldir = $agi->get_variable(“ASTSPOOLDIR”);
$callfile = $agi->get_variable(“CALLFILENAME”);
$fullpath = $astspooldir[‘data’].“/monitor”.$datepath.$callfile[‘data’].“.wav”;

You can add some kind of file name or identifier wherever you want, anything you can think of.
Good Luck!

1 Like

I got some struggles with the

“…your curl specific stuff…”

i tried this but no luck atm.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $recording);

Am i close to goal?


the “fullpath” is ok and the “helloworld” curl work to.

But i don’t know what can i do with this path to upload it correctly

You might be close, I don’t know what curlopts are needed for your setup, i.e. https, auth, etc.

This could be your function to curl outside of PHP but you could run php curl if you want:

function curl_upload($recording) {
  $url = "";
  global $agi, $auth;
  $command = " curl -s -k -X POST \
  ".$url." \
  -H 'Authorization: Basic $auth' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@$recording' \
  -F 'title=Call Recording' ";
  $agi->verbose("Upload command: ".$command);
  return exec($command);
1 Like

Ok, we did it !

function curl_upload($recording) {
$target_url = ‘’;
$post = array(‘extra_info’ => ‘123456’,‘file_contents’=>’@’.$recording);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;

Thank you @stevehillin

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.