[RESOLVED]Twilio MediaUrl{N} – cannot get the data

EDIT: got it fixed.

MediaUrl{N} means MediaUrl0, ….. MediaUrlN

I am having trouble with implementing the new MMS capabilities of Twilio.

MMS is just a SMS with a picture attached.

My listener for SMS works fine receiving SMS:

string from = Request["From"];
string smsbody = Request["Body"];

Twilio sends additional information if a picture was attached:

Twilio also sends the following parameters when there is media, such as images, associated with the message:
Parameter Description
MediaContentType{N} The ContentTypes for the Media stored at MediaUrl{N}. The order of MediaContentType{N} matches the order of MediaUrl{N}. If more than one media element is indicated by NumMedia than MediaContentType{N} will be used, where N is the count
of the Media

MediaUrl{N} A URL referencing the content of the media received in the Message. If more than one media element is indicated by NumMedia than MediaUrl{N} will be used, where N is the count of the Media

I am getting nummedia just fine to:

int nummedia = Request["NumMedia"].AsInt();

My problem is with MediaUrl{N} and MediaContentType{N}

Here is my code:

string mediauri = "";
string mediaurl = "";
for (int nm = 0; nm < nummedia; nm++) 
    {
    mediauri = Request["MediaContentType{nm}"];
    mediaurl = Request["MediaUrl{nm}"];

some db activities here.
    }

mediauri and mediaurl are empty!

I am not sure what the problem is. I have tried changing to [ ]  from { } but that did not help.

Any suggestions would be appreciated.

TIA

Robert

Hi Robert,

For this issue, I suggest that you could use the developer tool to check whether the request data contain the data with that key.

Base on my test, it can recognize that parameter key.

@{
    string s=Request["MediaContentType{nm}"];
}

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <div>value: @s</div>
        <form method="post">
            <input type="text" name="MediaContentType{nm}" value=""/>
            <input type="submit" value="submit"/>
        </form>
    </body>
</html>

Best Regards

Starain

Try changing

wavemaster

mediauri = Request["MediaContentType{nm}"];
mediaurl = Request["MediaUrl{nm}"];

To

mediauri = Request["MediaContentType" + nm];
mediaurl = Request["MediaUrl" + nm];

Hello,

Add 2 string variables:

string s1 = "";
string s2 = "";

And change the FOR block as follows:

for (int nm = 0; nm < nummedia; nm++) 
    {
    s1 = "MediaContentType" + nm.ToString();
    mediauri = Request[s1];
    s2 = "MediaUrl" + nm.ToString();
    mediaurl = Request[s2];
    }
}

Hope it works..

Leave a Reply