X/Twitter Media Upload

Upload media files to X/Twitter with proper formatting and metadata

Overview

This node uploads media files to X (formerly Twitter) with proper formatting and metadata. It supports multiple input types for the media file, including URLs, base64-encoded data, and binary data from previous nodes. After uploading the media, it can optionally create a tweet immediately using the uploaded media.

Common scenarios:

  • Automating media uploads to X/Twitter as part of a social media workflow.
  • Posting images or videos programmatically from other data sources or generated content.
  • Integrating media upload and tweeting in one step to streamline content publishing.

Practical examples:

  • Uploading a promotional video from a URL and posting a tweet announcing a new product.
  • Taking an image generated by another node in n8n (binary data), uploading it to X, and tweeting it with a caption.
  • Uploading a base64-encoded GIF and creating a tweet with it instantly.

Properties

Name Meaning
Input Type The format of the media input. Options: URL, Base64, Binary.
Media Source The URL or base64 string of the media file (shown if Input Type is URL or Base64).
Binary Property The name of the binary property containing the media file (shown if Input Type is Binary).
Media Type The MIME type of the media being uploaded. Options: image/png, image/jpeg, image/gif, video/mp4, video/quicktime.
Create Tweet Whether to immediately create a tweet with the uploaded media. Boolean true/false.
Tweet Text The text content of the tweet (shown only if Create Tweet is true).

Output

The node outputs a JSON object with the following fields:

  • mediaId: The ID of the uploaded media on X.
  • mediaUrl: A URL linking to the media's page on X.
  • userId: The ID of the authenticated user who uploaded the media.
  • If a tweet was created:
    • tweetId: The ID of the created tweet.
    • tweetUrl: A URL linking directly to the created tweet.

The output does not include binary data; it provides metadata and links related to the uploaded media and optional tweet.

Dependencies

  • Requires an API authentication token credential for X/Twitter with OAuth2 access.
  • Uses the official Twitter API v2 client library for media upload and tweeting.
  • Relies on helper classes to handle different input types (URL, Base64, Binary).
  • No additional environment variables are explicitly required beyond the API credentials.

Troubleshooting

  • No access token available error: This occurs if the OAuth2 credential is missing or invalid. Ensure the API key/token is correctly configured and authorized.
  • Invalid MP4 file error: When uploading MP4 videos, the node checks the file header. If the file is not a valid MP4, it throws an error. Verify the media source is a proper MP4 file.
  • Media upload failures: Could be due to network issues, invalid media type, or API rate limits. Check the media format and your API usage quotas.
  • Tweet creation errors: If the tweet text is invalid or the media upload failed, the tweet creation will fail. Confirm the media upload succeeded before enabling tweet creation.

Links and References

Discussion