Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now

メニュー

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Media Resource

The Media resource represents a piece of media, such as an image, that is associated with a message.

Twilio will create a Media resource and store the contents of the media when the following events occur:

  1. You send a message with an image via Twilio
  2. You receive media on one of your Twilio phone numbers

Twilio will keep that media around until you issue an HTTP DELETE on that instance.

Messages sent via Twilio can include up to 10 media files that have a total size of up to 5MB. Twilio will resize images as necessary for successful delivery based on carrier specifications. Messages with over 5MB of media will not be accepted.

Media properties

Names in PHP format
accountSid
sid<AC> Not PII

The SID of the Account that created this Media resource.

contentType
文字列 Not PII

デフォルトのメディアのMIMEタイプ例 : image/jpeg,image/png,image/gif

dateCreated
date_time<rfc2822> Not PII

The date and time in GMT that this resource was created specified in RFC 2822 format.

dateUpdated
date_time<rfc2822> Not PII

The date and time in GMT that this resource was last updated, specified in RFC 2822 format.

parentSid
sid<MM> Not PII

The SID of the resource that created the media.

sid
sid<ME> Not PII

The unique string that that we created to identify this Media resource.

uri
uri Not PII

The URI of this resource, relative to https://api.twilio.com.

Fetch a Media resource

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

Returns a single media resource using one of several representations:

既定: content-type

Without an extension, the media is returned using the mime-type provided when the media was generated.

GET /2010-04-01/Accounts/AC.../Message/MM.../Media/ME557ce644e5ab84fa21cc21112e22c485

代替: XML

URI に「.xml」をつけると、通常の XML 表現を返します。 たとえば、次のようになります。

GET /2010-04-01/Accounts/AC.../Message/MM.../Media/ME557ce644e5ab84fa21cc21112e22c485.xml
<TwilioResponse>
 <Media>
   <Sid>ME557ce644e5ab84fa21cc21112e22c485</Sid>
   <AccountSid>ACda6f1e11047ebd6fe7a55f120be3a900</AccountSid>
   <ParentSid>MM8dfedb55c129dd4d6bd1f59af9d11080</ParentSid>
   <ContentType>image/jpeg</ContentType>
   <DateCreated>Fri, 17 Jul 2009 01:52:49 +0000</DateCreated>
   <DateUpdated>Fri, 17 Jul 2009 01:52:49 +0000</DateUpdated>
   <Uri>/2010-04-01/Accounts/ACda6f1e11047ebd6fe7a55f120be3a900/Message/MM8dfedb55c129dd4d6bd1f59af9d11080/Media/ME557ce644e5ab84fa21cc21112e22c485.xml</Uri>
 </Media>
</TwilioResponse>

代替: JSON

URI に「.JSON」をつけると、JSON 表現を返します。 たとえば、次のようになります。

GET /2010-04-01/Accounts/AC.../Message/MM.../Media/ME557ce644e5ab84fa21cc21112e22c485.json
{
    "sid": "ME557ce644e5ab84fa21cc21112e22c485",
    "account_sid": "ACda6f1e11047ebd6fe7a55f120be3a900",
    "parent_sid": "MM8ff928b2451c0db925bd2d581f0fba79",
    "content_type": "image/jpeg",
    "date_created": "Fri, 26 Apr 2013 05:41:35 +0000",
    "date_updated": "Fri, 26 Apr 2013 05:41:35 +0000",
    "uri": "/2010-04-01/Accounts/ACda6f1e11047ebd6fe7a55f120be3a900/Message/MM8dfedb55c129dd4d6bd1f59af9d11080/Media/ME557ce644e5ab84fa21cc21112e22c485.json"
}
パラメーター
Names in None format
account_sid
必須
GET sid<AC> Not PII

The SID of the Account that created the Media resource(s) to fetch.

message_sid
必須
GET sid<MM> Not PII

The SID of the Message resource that this Media resource belongs to.

sid
必須
GET sid<ME> Not PII

The Twilio-provided string that uniquely identifies the Media resource to fetch

        
        
        
        

        Because the stored media URLs are useful for many external applications, they are public and do not require HTTP Basic Auth to access. This allows you to embed the URL in a web application without revealing your Twilio API credentials.

        These URLs are long and hard to guess, so the contents of the media should be private unless you choose to distribute the URL.

        Read multiple Media resources

        GET
        https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json

        メッセージに関連するメディアのリストを返します。このリストはページ情報を含みます。

        Filter by date created

        You may limit the list of Message Media to media created on a given date. Provide the following query string parameter to your API call:

        パラメーター
        Names in None format
        account_sid
        必須
        GET sid<AC> Not PII

        The SID of the Account that created the Media resource(s) to read.

        message_sid
        必須
        GET sid<MM> Not PII

        The SID of the Message resource that this Media resource belongs to.

        date_created
        オプション
        GET date_time_inequality<iso8601> Not PII

        The date_created value, specified as YYYY-MM-DD, of the resources to read. You can also specify inequality, such as DateCreated<=YYYY-MM-DD for media generated at or before midnight on a date, and DateCreated>=YYYY-MM-DD for media generated at or after midnight on a date.

        例 1
              
              
              
              
              Return the list of media associated with your message

              Read Media

              Return the list of media associated with your message

              Delete a Media resource

              削除する
              https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json

              メディアをアカウントから削除。

              削除に成功すると、ボディーのない HTTP 204 (No Content) レスポンスを返します。

              パラメーター
              Names in None format
              account_sid
              必須
              削除する sid<AC> Not PII

              The SID of the Account that created the Media resource(s) to delete.

              message_sid
              必須
              削除する sid<MM> Not PII

              The SID of the Message resource that this Media resource belongs to.

              sid
              必須
              削除する sid<ME> Not PII

              The Twilio-provided string that uniquely identifies the Media resource to delete

              例 1
                    
                    
                    
                    

                    ヒントとテクニック

                    • Twilio will attempt to cache the media file the first time it is used. This may add a slight delay in sending the message.
                    • HTTPヘッダーが許可している(EtagおよびLast-Modifiedヘッダー経由)場合、Twilioはファイルのキャッシュを行います。Cache-Control: no-cacheを伴ったレスポンスを行うと、Twilioはファイルが変更されたかどうかを常に確認するようになり、ご使用のWebサーバーが新しいバージョンのファイルでレスポンスするか、それとも403 Not Modifiedを返してTwilioにキャッシュされたバージョンを使用させることができます。
                    Rate this page:

                    ヘルプが必要ですか?

                    誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。