uploadAppend method
The APPEND
command is used to upload a chunk (consecutive byte range) of
the media file. For example, a 3 MB file could be split into 3 chunks of
size 1 MB, and uploaded using 3 APPEND
command requests. After the
entire file is uploaded, the next step is to call the FINALIZE
command.
mediaId
: The UploadInit.mediaIdString returned from the INIT
command.
media
: The raw binary file content being uploaded. It must be <= 5 MB.
segmentIndex
: An ordered index of file chunk. It must be between 0-999
inclusive. The first segment has index 0, second segment has index 1, and
so on.
See https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append.
Implementation
Future<void> uploadAppend({
required String mediaId,
required List<int> media,
required int segmentIndex,
}) async {
final params = <String, String>{}
..addParameter('command', 'APPEND')
..addParameter('media_id', mediaId)
..addParameter('segment_index', segmentIndex);
await client.multipartRequest(
Uri.https('upload.twitter.com', '1.1/media/upload.json', params),
files: [MultipartFile.fromBytes('media', media)],
);
}