Uploads a media file to X (formerly Twitter) for attachment to a tweet.

This function uploads a media file to X, which can then be attached to a tweet. It takes a Buffer object containing the media file and its MIME type as parameters, and returns a promise that resolves to a MediaUploadResponse object containing details about the uploaded media.

post/upload

Request body

Response

Successful media upload

media_idnumber

The media ID as a number.

media_id_stringstring required

The media ID as a string.

sizenumber

The size of the media file in bytes.

expires_after_secsnumber

The number of seconds until the uploaded media expires.

Changes