2
votes

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

1
Twilio evangelist here. Pretty sure there is no way to get the direct S3 URL from the API. Can I ask why getting the S3 URL is better for you? - Devin Rader
I need the MMS images to be viewable to whatever agent gets the MMS. I figured it would be easiest to just display the URL link twilio provides. I could download the image but I see no way to do that with the API either, it seems that unless I go to the link and login to the twilio API in my browser there is no way to get the image - StevenDStanton
You should just be able to use the API URL. Twilio will return the media using whatever content type we received with the image when the message was sent to us. twilio.com/docs/api/rest/media#instance-get - Devin Rader
Is there anyway to do this with the libraries provided for Node.js? From what I have seen the only way to do this would be to use curl to access the media resource which I was trying to avoid. - StevenDStanton
It would be convenient to have a direct link to the S3 to display the image. Otherwise we have to download the media and then re-serve it on our servers - Randall Coding

1 Answers

3
votes

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.