動画や大きなtailored audiencesなどをアップロードする際にはファイルサイズが64MBを超えることがあるので、 分割アップロードを使う必要があります。
分割アップロードには二段階のプロセスがあります。まず、全コンテンツの長さとコンテンツタイプを付与したリクエストを作成し、Location情報を取得します。
次に、最初の応答に記載されているLocation宛に64MB未満のサイズの チャンクをアップロードします。
チャンクのサイズはX-TON-Min-Chunk-Sizeの倍数でなければならないので注意してください (最後のアップロード時以外)。
アップロードするチャンクのサイズには、30秒の枠内でチャンクのアップロードを完了できるサイズを指定してください。 例えば: あなたの使用できるアップロード帯域幅が 10Mビット/秒の場合、アップロードするチャンクのサイズ は 37.5 MB未満を使用してください。
以下が、分割アップロードで最初に作成するリクエストの例です:
POST /1.1/ton/bucket/{bucket}?resumable=true HTTP/1.1
Host: ton.twitter.com
Content-Length: 0
Content-Type: video/mp4
X-TON-Content-Type: video/mp4
X-TON-Content-Length: 516928473
Authorization: OAuth oauth_consumer_key="XXXXXXXXXX", oauth_nonce="XXXXXXXXXX", oauth_signature="XXXXXXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1426878860", oauth_token="XXXXXXXXXX", oauth_version="1.0"
Resumable UploadSome uploads such as videos or large tailored audiences might be greater than 64MB and should use resumable upload. Resumable upload is a 2-step process. First, make a request with the total content length and content type which returns a Please choose an upload chunk size such that you can reliable upload the chunk in a 30-second window. For example: If you have dedicated upload bandwidth of 10Mbit/s, please use an upload chunk size smaller than 37.5 MB. An example resumable upload initialization request:
POST /1.1/ton/bucket/{bucket}?resumable=true HTTP/1.1
Host: ton.twitter.com
Content-Length: 0
Content-Type: video/mp4
X-TON-Content-Type: video/mp4
X-TON-Content-Length: 516928473
Authorization: OAuth oauth_consumer_key="XXXXXXXXXX", oauth_nonce="XXXXXXXXXX", oauth_signature="XXXXXXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1426878860", oauth_token="XXXXXXXXXX", oauth_version="1.0"
|
応答は以下のようになります:
HTTP/1.1 201 OK
Date: Wed, 05 Nov 2014 22:50:16 UTC
Location: /1.1/ton/bucket/{bucket}/SzFxGfAg_Zj.mp4?resumable=true&resumeId=28401873
X-TON-Max-Chunk-Size: {チャンクの最大サイズ}
X-TON-Min-Chunk-Size: {チャンクの最少サイズ。最後に送信するチャンクは除く}
Expires: Wed, 05 Nov 2014 23:50:16 UTC
Content-Length: 0
|
The response:
HTTP/1.1 201 OK
Date: Wed, 05 Nov 2014 22:50:16 UTC
Location: /1.1/ton/bucket/{bucket}/SzFxGfAg_Zj.mp4?resumable=true&resumeId=28401873
X-TON-Max-Chunk-Size: {max chunk size}
X-TON-Min-Chunk-Size: {min chunk size, except the last chunk}
Expires: Wed, 05 Nov 2014 23:50:16 UTC
Content-Length: 0
|
最初のリクエストには以下のヘッダが必要です:
Authorization: 3-legged authorizationを参照してください
Content-Length: 0を設定してください。
Content-Type: アップロードするアセットの Content-Type 。参照 [1]
X-TON-Content-Type: Content-Type と同じ値を設定してください。
X-TON-Content-Length: アップロードするアセットの合計バイト数
|
The initialization request requires the following headers:
|
最初の応答に格納されているLocation の情報は、後続のリクエスト全てで使うので保存しておいてください。
初期化後に、チャンクをアップロードできます。
以下が動画を分割アップロードするリクエストの例です:
PUT /1.1/ton/bucket/{bucket}/SzFxGfAg_Zj.mp4?resumable=true&resumeId=28401873 HTTP/1.1
Authorization: // oAuth1.0a (3-legged) の詳細をここに記載
Content-Type: video/mp4
Content-Length: {このリクエストで転送するバイト数}
Content-Range: bytes {starting position, inclusive, 0-indexed}-{end position, inclusive}/{total content length}
{video bytes}
|
The initialization response contains a After initialization, chunks can be uploaded. An example resumable video upload request:
PUT /1.1/ton/bucket/{bucket}/SzFxGfAg_Zj.mp4?resumable=true&resumeId=28401873 HTTP/1.1
Authorization: // oAuth1.0a (3-legged) details here
Content-Type: video/mp4
Content-Length: {number of bytes transferred in this request}
Content-Range: bytes {starting position, inclusive, 0-indexed}-{end position, inclusive}/{total content length}
{video bytes}
|
最後の応答を除き、各チャンクをアップロードした際の応答は以下のようになります:
HTTP/1.1 308 Resume Incomplete
Date: Wed, 05 Nov 2014 23:20:10 UTC
Content-Length: 0
Range: 0-{現時点でアップロードできた長さ}
|
The response for each chunk except the last:
HTTP/1.1 308 Resume Incomplete
Date: Wed, 05 Nov 2014 23:20:10 UTC
Content-Length: 0
Range: 0-{current uploaded length}
|
最後のチャンクをアップロードした際の応答は以下のようになります:
HTTP/1.1 201 Created
Date: Wed, 05 Nov 2014 23:30:10 UTC
Location: /1.1/ton/bucket/{bucket}/SzFxGfAg_Zj.mp4
Content-Length: 0
アップロードが完了したら、後でTwitter APIの呼び出しで使う場合に備えて Location ヘッダを保存してください。
|
The response for the last chunk:
HTTP/1.1 201 Created
Date: Wed, 05 Nov 2014 23:30:10 UTC
Location: /1.1/ton/bucket/{bucket}/SzFxGfAg_Zj.mp4
Content-Length: 0
Once completed, the |