Inside an Asterisk application (dialplan) I need to insert in a MSSQL database a sound file. I’m using freeTDS to communicate with the DB.
The example table is called “testblob”
(id int identity, name varchar(50), audiofile varbinary(MAX))
Im trying with this code:
exten => s,n,Set(arch=${FILE(/var/lib/asterisk/sounds/custom/myFile.wav)})
exten => s,n,Verbose(${arch})
exten => s,n,Set(RESULT=${SHELL(echo -e use "AVL \\ngo\\ninsert into testblob (name, audiofile) values ('mar',${arch})\\ngo"|tsql -H x.x.x.x -p 1433 -U sa -P x)})
But is not working most certainly because of the “special chars” inside de ${arch} variable. I know that inside $arch is the file info, but I guess I need to read it on binary or 64encode it or something like that.
Question is: Is there any way to insert this myFile.wav directly from the shell? Something like:
echo -e use "AVL \\ngo\\ninsert into testblob (name, audiofile) values ('mar',####MAGIC GOES HERE TO READ MYFILE.WAV###)\\ngo"|tsql -H x.x.x.x -p 1433 -U sa -P x
Ok, so the way to do it in a single line is using base64, like this:
Note the use of “( )” and “|” and the trick using “tr -d” to remove the CR leaved behind by the base64 command.
Hope this helps someone else