Check for file size before trying to send fax
This commit is contained in:
parent
4870aca1fd
commit
f9c39da3bb
11
fax.sh
11
fax.sh
|
@ -15,6 +15,13 @@ FILE=$1
|
|||
echo -n "Sending file ${FILE} "
|
||||
REC=$(echo "$2" | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:')
|
||||
echo "to $REC"
|
||||
#Checking for file size:
|
||||
SIZE=$(ls -l | cut -d " " -f5)
|
||||
if [ $SIZE -gt 10485760 ]
|
||||
then
|
||||
echo "File too big. Cannot be more than 10MB."
|
||||
exit 2
|
||||
fi
|
||||
#Needs to be base64 encoded:
|
||||
CONTENT=$(base64 $FILE -w 0)
|
||||
if [ -z "$CONTENT" ];
|
||||
|
@ -25,7 +32,9 @@ fi
|
|||
#save payload to tempfile to prevent curl from throwing 'argument list too long' error.
|
||||
echo '{"faxlineId":"f0", "recipient":"'${REC}'", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}' > /tmp/sipgatedata.txt
|
||||
#Send fax
|
||||
FAXID=$(curl --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data @/tmp/sipgatedata.txt "https://api.sipgate.com/v2/sessions/fax" -s | jq '.sessionId' | sed -e 's:"::g' )
|
||||
REPLY=$(curl --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data @/tmp/sipgatedata.txt "https://api.sipgate.com/v2/sessions/fax" -s)
|
||||
FAXID=$(echo $REPLY | jq '.sessionId' | sed -e 's:"::g' )
|
||||
echo $REPLY > /tmp/sipgatereply.txt
|
||||
#remove tempfile
|
||||
rm /tmp/sipgatedata.txt
|
||||
if [ -z $FAXID ]
|
||||
|
|
|
@ -68,5 +68,5 @@ else
|
|||
fi
|
||||
if [ $DF = true ]
|
||||
then
|
||||
grep -v $ID $BASEPATH/.fax_history > $BASEPATH/.fax_history
|
||||
echo "$(grep -v "^$ID$" $BASEPATH/.fax_history)" > $BASEPATH/.fax_history
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue