Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Conversations Media Resource


The Media resource in Twilio's Media Content Service allows you to upload/download files for use in other Twilio products. You can attach these media files to Conversation Messages as part of the Media Messaging feature.

Note: The Media REST resource is accessed via a separate sub-domain from Chat and other Twilio products. The base URL for Media via the Media Content Service (MCS) is:


_10
https://mcs.us1.twilio.com/v1


Authentication

authentication page anchor

HTTP requests to the REST API are protected with HTTP Basic authentication, just like other Twilio REST APIs. To learn more about how Twilio handles authentication, please refer to our security documentation. In short, you use your Twilio account SID as the username and your Auth Token as the password for HTTP Basic authentication.


_10
curl -G https://mcs.us1.twilio.com/v1/Services \
_10
-u '[YOUR ACCOUNT SID]:[YOUR AUTH TOKEN]'

You can find your Account SID and Auth Token in the admin console(link takes you to an external page). Alternately, you can also use API keys and secrets to authenticate REST API requests. You can also manage API key pairs in the console(link takes you to an external page).

Note: The Media endpoint is not represented in the Twilio Helper Libraries or Twilio CLI at this time.


Each Media resource instance has these properties:

namedescription
sidA 34-character string that uniquely identifies this resource.
account_sidThe unique id of the Account responsible for this message.
service_sidThe unique id of the Chat Service this message belongs to.
date_createdThe date that this resource was created.
date_updatedThe date that this resource was last updated, null if the message has not been edited.
channel_sidThe unique id of the Conversation (same as the underlying Chat Channel) containing the Message that this media instance was added to.
message_sidThe unique id of the Conversation Message this media instance was added to.
sizeThe size of the file this Media instance represents in BYTES
content_typeThe MIME type of the file this Media instance represents. Please refer to the MIME Types(link takes you to an external page) for a list of valid MIME types.
file_nameThe filename of the underlying media file as specified when uploaded
authorThe identity of the User that uploaded the Media instance. This is automatically set to sender when using the REST API.
urlAn absolute URL for this media instance
linksLinks to access the underlying media file (content) and a temporary URL to use to access this (content_direct_temporary)

Create/Upload a new Media resource

createupload-a-new-media-resource page anchor

_10
POST /Services/{Chat Service SID}/Media

Note: The Chat Service SID must be the Chat Service Instance that this Media instance will be used for. You can find the Chat Service SID as a property of the Conversation to which you want to add a new media message.

To create a new media instance, you should upload the media file itself as content on the POST request. (See Curl Example below.)

Ultimately, this will be converted into a POST request, containing the following headers and the file itself as the request body.

Headers

headers page anchor
namedescription
Content-TypeThe MIME type of the file this Media instance represents. Please refer to the MIME Types(link takes you to an external page) for a list of valid MIME types. This should be set explicitly by the API caller or automatically detected by the client.
Content-SizeThe size of the media (the file) being uploaded in bytes

The body or content of the POST must be the file itself in binary format.


_10
curl -u "<account_sid>:<account_secret>" --data-binary @<filename.png> -H "Content-Type: <content-type of upload>" https://mcs.us1.twilio.com/v1/Services/<chat_service_sid>/Media


Retrieve a Media resource

retrieve-a-media-resource page anchor

You can retrieve an uploaded Media resource by issuing a GET request with the SID of the media instance:


_10
GET /Services/{Chat Service SID}/Media/{Media SID}

Curl Example for retrieving a media resource

curl-example-for-retrieving-a-media-resource page anchor

_10
curl -u “<account_sid>:<account_secret>” -G https://mcs.us1.twilio.com/v1/Services/<chat_service_sid>/Media/<Media SID>


Rate this page: