Accessing Twilio MMS images

左心房为你撑大大i 提交于 2019-12-11 03:54:18

问题


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:


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.



来源:https://stackoverflow.com/questions/30383166/accessing-twilio-mms-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!