StevenDStanton
StevenDStanton

Reputation: 866

Accessing Twilio MMS images

In Twilio when the ImageMedia URL is given it is accessing the twilio api as follows

https://api.twilio.com/2010-04-01/Accounts/{account sid}/Messages/{message sid}/Media/{media sid}

If you have manually logged into the twilio API that url redirects to the image located at

http://media.twiliocdn.com.s3-website-us-east-1.amazonaws.com/{account sid}/{image id}

How can I get the direct image ID from the twilio API to include in my web app?

I am working with node.js and every time I try to poll the media resources all I receive is the link to the api.twilio.com and not the mdeia.twiliocdn.com

Upvotes: 2

Views: 2076

Answers (1)

StevenDStanton
StevenDStanton

Reputation: 866

The library doesn't handle this feature that I can find

However, if anyone else comes across the same problem here is the solution

install request.

Then just get NumMedia and MediaUrl parameters...

if(req.body.NumMedia > 0){ 
   var request = require('request')
    request.get(req.body.MediaUrl0).auth(config.twilio.sid, config.twilio.auth, false).pipe(fs.createWriteStream("/var/www/app/public/mms/" + sid + '1.jpg' ));
 }

Remember that up to 10 images can be sent so you would just need the logic too gather those extra images.

Upvotes: 3

Related Questions