XClient.Media (XClient v1.0.0)

Copy Markdown View Source

Media upload operations for X API v1.1.

Supports uploading images, videos, and GIFs with chunked upload for large files.

Supported Media Types

  • Images: JPEG, PNG, GIF, WEBP
  • Videos: MP4
  • GIFs: Animated GIF

Size Limits

  • Images: 5 MB
  • GIFs: 15 MB
  • Videos: 512 MB

Examples

# Simple image upload
{:ok, media} = XClient.Media.upload("path/to/image.jpg")

# Upload with category
{:ok, media} = XClient.Media.upload("path/to/video.mp4",
  media_category: "tweet_video")

# Upload from binary data
{:ok, media} = XClient.Media.upload(image_binary,
  media_type: "image/png")

Summary

Functions

Adds metadata (like alt text) to uploaded media.

Uploads media using chunked upload (for large files).

Gets the processing status of uploaded media.

Functions

add_metadata(media_id, alt_text, client \\ nil)

Adds metadata (like alt text) to uploaded media.

Parameters

  • media_id - The media ID
  • alt_text - Alt text for accessibility (up to 1000 characters)

Examples

{:ok, _} = XClient.Media.add_metadata("123456789", "A beautiful sunset")

chunked_upload(media_path, opts \\ [], client \\ nil)

Uploads media using chunked upload (for large files).

Automatically used for files larger than 5 MB.

Parameters

  • media_path - Path to the media file
  • opts - Optional parameters (same as upload/3)

Returns

{:ok, media_object} with media_id_string.

upload(media, opts \\ [], client \\ nil)

Uploads media to X.

Parameters

  • media - File path or binary data
  • opts - Optional parameters
    • :media_category - Media category (tweet_image, tweet_gif, tweet_video, dm_image, dm_video, dm_gif)
    • :media_type - MIME type (auto-detected if not provided)
    • :additional_owners - List of user IDs who can use the media
    • :alt_text - Alt text for accessibility (up to 1000 characters)

Examples

{:ok, media} = XClient.Media.upload("image.jpg")
{:ok, media} = XClient.Media.upload("video.mp4", media_category: "tweet_video")
{:ok, media} = XClient.Media.upload(binary_data, media_type: "image/png")

Returns

{:ok, media_object} with media_id_string that can be used in tweets.

upload_status(media_id, client \\ nil)

Gets the processing status of uploaded media.

Used for videos and GIFs that require processing.

Parameters

  • media_id - The media ID to check

Examples

{:ok, status} = XClient.Media.upload_status("123456789")

Returns

Processing status with state: "pending", "in_progress", "failed", or "succeeded"