-
Notifications
You must be signed in to change notification settings - Fork 217
Upload
Twitter allows developers to upload files on their servers so that they can be used in tweets. Twitter has a limited file format that they support:
- Images : PNG, JPEG, WEBP and GIF. Animated GIFs are supported.
- Videos : MP4
If you want to learn more about the supported formats and video recommendations visit Twitter upload documentation.
Tweetinvi offers various solution to upload files on Twitter. A successful upload will create an IMedia that can be attached to a tweet publication.
var image = File.ReadAllBytes("path");
var media = Upload.UploadImage(image);
IMPORTANT : Videos can only be published using the chunked upload endpoint.
var video = File.ReadAllBytes("path");
var media = Upload.UploadVideo(video);
Chunked upload allows developer to upload videos but it more specifically allow developers to upload any binary in multiple steps.
For phone app developers such a feature can be incredibly useful as you will no longer have to wait for an entire file to be uploaded at once.
var uploader = Upload.CreateChunkedUploader();
// Initialize the upload
var initSucceeded = uploader.Init("video/mp4", totalBinaryLength);
// Upload your different chunks
var success1 = uploader.Append(firstChunk);
if (!success1)
{
RetryUpload(uploader, firstChunk);
}
var success2 = uploader.Append(secondChunk);
// When you have uploaded all your chunks
var media = uploader.Complete();