uploadInit method
- required int totalBytes,
- required String mediaType,
- String? mediaCategory,
- List<
String> ? additionalOwners, - TransformResponse<
UploadInit> transform = defaultUploadInitTransform,
The INIT command request is used to initiate a file upload session. It
returns a mediaId which should be used to execute all subsequent
requests. The next step after a successful return from INIT command is
the APPEND command.
See https://developer.twitter.com/en/docs/media/upload-media/uploading-media/media-best-practices for constraints and requirements on media files.
totalBytes: The size of the media being uploaded in bytes.
mediaType: The MIME type of the media being uploaded.
mediaCategory: A string enum value which identifies a media usecase.
This identifier is used to enforce usecase specific constraints (e.g. file
size, video duration) and enable advanced features.
additionalOwners: A list of user IDs to set as additional owners allowed
to use the returned mediaId in Tweets or Cards. Up to 100 additional
owners may be specified.
transform: Can be used to parse the request. By default, the response is
parsed in an isolate.
See https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-init.
Implementation
Future<UploadInit> uploadInit({
required int totalBytes,
required String mediaType,
String? mediaCategory,
List<String>? additionalOwners,
TransformResponse<UploadInit> transform = defaultUploadInitTransform,
}) async {
final body = <String, String>{}
..addParameter('command', 'INIT')
..addParameter('total_bytes', totalBytes)
..addParameter('media_type', mediaType)
..addParameter('media_category', mediaCategory)
..addParameter('additional_owners', additionalOwners);
return client
.post(
Uri.https('upload.twitter.com', '1.1/media/upload.json'),
body: body,
)
.then(transform);
}