This guide walks you through uploading videos and large media files using the chunked upload. Reference for the X API v2 standard tier covering quickstart.
This guide walks you through uploading videos and large media files using the chunked upload workflow.For video or large media uploads, you must:
INIT — Initialize the upload and get a media_id
APPEND — Upload each chunk of the file
FINALIZE — Complete the upload
STATUS — (If needed) Wait for processing to complete
from xdk import Clientimport timeclient = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")# Wait for processing to completewhile True: response = client.media.get_status(media_id=media_id) state = response.data.processing_info.state if state == "succeeded": print("Media ready!") break elif state == "failed": print("Processing failed") break else: check_after = response.data.processing_info.check_after_secs print(f"Processing... checking again in {check_after}s") time.sleep(check_after)
import { Client } from "@xdevplatform/xdk";const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });// Wait for processing to completewhile (true) { const response = await client.media.getStatus({ mediaId }); const state = response.data?.processing_info?.state; if (state === "succeeded") { console.log("Media ready!"); break; } else if (state === "failed") { console.log("Processing failed"); break; } else { const checkAfter = response.data?.processing_info?.check_after_secs ?? 1; console.log(`Processing... checking again in ${checkAfter}s`); await new Promise((r) => setTimeout(r, checkAfter * 1000)); }}
Processing states:pending → in_progress → succeeded or failed
Once processing is complete, create a Post with the media:
cURL
curl -X POST "https://api.x.com/2/tweets" \ -H "Authorization: Bearer $USER_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "text": "Check out this video!", "media": { "media_ids": ["1880028106020515840"] } }'
from xdk import Clientclient = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")# Create Post with mediaresponse = client.posts.create( text="Check out this video!", media={"media_ids": [media_id]})print(f"Posted: {response.data.id}")
import { Client } from "@xdevplatform/xdk";const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });// Create Post with mediaconst response = await client.posts.create({ text: "Check out this video!", media: { mediaIds: [mediaId] },});console.log(`Posted: ${response.data?.id}`);