uploadMedia abstract method

Future<TwitterResponse<UploadedMediaData, void>> uploadMedia({
  1. required File file,
  2. MediaCategory category = MediaCategory.tweet,
  3. String? altText,
  4. List<String>? additionalOwners,
  5. dynamic onProgress(
    1. UploadEvent event
    )?,
  6. dynamic onFailed(
    1. UploadError error
    )?,
})

The integrated endpoint for uploading images, GIFs, and videos to Twitter.

This endpoint allows large files to be uploaded, divided into the appropriate size and securely uploaded to Twitter. If the size of the file to be uploaded is large, it may take some time for the upload to complete, but this method internally polls for any waiting if it's required, and the caller of this method does not need to be aware of the status of the upload.

If an error occurs when uploading media, TwitterUploadException is always thrown.

Caution

This method uses the v1.1 endpoint. Therefore, the arguments and returned object of this method may change in the future when the v2.0 endpoint for uploading images is released.

Parameters

  • file: The raw binary media content (image, gif, video) being uploaded.

  • category: Specify whether the media to be uploaded is related to tweets or direct messages. The default value is MediaCategory.tweet, and this option is not necessary if you are uploading media to be attached to a tweet. However, for media to be attached to a direct message, be sure to specify MediaCategory.directMessage for this option.

  • altText: Additional descriptive text to be added to images and GIFs. Currently, this option is available only for images and GIFs; if the media file being uploaded is a video, this option will be ignored at runtime. Also, the text must be <= 1000 chars.

  • additionalOwners: A list of user IDs to set as additional owners allowed to use the returned media id in Tweets or Cards. Up to 100 additional owners may be specified.

  • onProgress: This callback function allows the user to check the progress of an upload when a large volume of media is uploaded. This callback function is called each time after polling the Twitter upload server. If the upload fails, this callback function is not called.

  • onFailed: This callback function is called when the progress of a media upload is polled and the media upload has failed.

Endpoint Url

Authentication Methods

  • OAuth 1.0a

Reference

Implementation

Future<TwitterResponse<UploadedMediaData, void>> uploadMedia({
  required File file,
  MediaCategory category = MediaCategory.tweet,
  String? altText,
  List<String>? additionalOwners,
  Function(UploadEvent event)? onProgress,
  Function(UploadError error)? onFailed,
});