简体   繁体   English

如何使用 Node.js 从 Twilio whatsapp API 下载图像

[英]How to download an image from Twilio whatsapp API with Node.js

My goal is to get the image from Twilio api to store it somewhere else because Twilio deletes media after 4h.我的目标是从 Twilio api 获取图像以将其存储在其他地方,因为 Twilio 会在 4 小时后删除媒体。 (See here) (看这里)

I'm using node and I have read https://www.twilio.com/docs/sms/api/media-resource#fetch-a-media-resource我正在使用节点,我已经阅读了https://www.twilio.com/docs/sms/api/media-resource#fetch-a-media-resource

...and it says that to do a request to this URL without the "json" extension should return the media with its original MIME type ...它说要在没有“json”扩展名的情况下对该 URL 进行请求,应返回具有其原始 MIME 类型的媒体

https://api.twilio.com/2010-041/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json https://api.twilio.com/2010-041/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json

However, i need auth, so I need to use但是,我需要身份验证,所以我需要使用

const client = require('twilio')(accountSid, authToken);

How can I fetch the image?我怎样才能获取图像? Any sample code to achieve it?任何示例代码来实现它? In the docs seem to do it without auth.在文档中似乎没有授权就可以做到。

UPDATE ----------------------------------------更新 - - - - - - - - - - - - - - - - - - - -

After accessing the MediaUrl0 on the browser, twilio redirects me to the following URL:在浏览器上访问MediaUrl0后,twilio 将我重定向到以下 URL:

https://s3-external-1.amazonaws.com/media.twiliocdn.com/{AccountSid}/{?} https://s3-external-1.amazonaws.com/media.twiliocdn.com/{AccountSid}/{?}

I was thinking of building my own URL but i dont know how to get the {?}我正在考虑构建自己的 URL,但我不知道如何获取{?}

You do not need authentication to retrieve media for an incoming sms .您不需要身份验证来检索传入短信的媒体。 They are all hosted (as of now on Aws S3) and accessible publicly through a (hard to guess) url.它们都是托管的(截至目前在 Aws S3 上)并可通过(难以猜测的)url 公开访问。 you can access them using any http client您可以使用任何 http 客户端访问它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM