Boudy
Boudy

Reputation: 21

Using local path in Twilio mediaURL

Does anyone know if a local path can be used to add a mediaURL to a Twilio SMS?

So:

MediaURL=file:///Users/Name/file.gif

Rather than:

MediaURL=https://server/file.gif

Upvotes: 2

Views: 2234

Answers (2)

abinash mishra
abinash mishra

Reputation: 11

You can host the files using ngrok and share the local files externally. Media url will be available for Twilio to access and will be shared to the recipients using twilio api.

Upvotes: 0

Jared Menard
Jared Menard

Reputation: 2756

You cannot use a local path. The media url has to be publicly accessible to Twilio's servers (ie it has to have a URL) so that the asset can be retrieved and added to the message. If it were accepted, that path would point to "/Users/Name/file.gif" on a random Twilio server. This is also why localhost based urls will not work with Twilio. If you are doing local development using Twilio you'll either need to use an IP address in your url or you'll need to use a service like ForwardHQ to provide a domain for your local webserver.

The MediaURL needs to be an absolute path, not a relative one.

Here is an example from Twilio's API docs using a MediaURL: https://www.twilio.com/docs/sms/send-messages#example-1

Here's the specific code snippet: https://www.twilio.com/docs/sms/send-messages?code-sample=code-send-a-message-with-an-image-url&code-language=rb&code-sdk-version=5.x

Update: our good friends at ForwardHQ have closed their doors. I am now using Ngrok.com to expose my local webserver to the internet.

Upvotes: 2

Related Questions