tags:

views:

199

answers:

2

I am trying to download an MP3 file from an AGI script written in Perl, however the file does not get downloaded. The strange thing is that if I try to download the same file from a plain Perl script it gets downloaded.

Here's my AGI code:

use Asterisk::AGI;

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();

$AGI->answer();

sub getAudioFile
{
    $filename = shift;

    open(FH, ">./audio.mp3") || die "error";

    binmode(FH);

    $AGI->verbose("Downloading audio file");

    $http_query = "curl http://www.something.com/cgi-bin/downloadfile.cgi? -d \"type=mp3&filename=$filename\" -s |";

    open (PIPER, $http_query) or die "sorry";

    $rets = "";

    while (<PIPER>)
    {
     $rets .= $_;
    }

    close(PIPER);
    chomp $rets;

    print FH $rets;
    close(FH);

    $AGI->verbose("Download complete");


}

getAudioFile('somefile.mp3');

$AGI->hangup();

What could be going wrong here ?

A: 

This line fails:

$AGI->answer();

Check the return value in the code.

From Asterisk::AGI - Simple Asterisk Gateway Interface Class:

$AGI->answer()

Executes AGI Command "ANSWER"

Answers channel if not already in answer state

Example: $AGI->answer();

Returns: -1 on channel failure, or 0 if successful

Peter Mortensen
A: 

Try running the "getAudioFile" portion of the perl script as the 'Asterisk' user (whatever is running asterisk). This will more closely emulate what is happening when Asterisk spawns the API.

Maybe it's a user-permissions error.

Dan Carlson