public void UploadMedias(IEnumerable <IMedia> medias, bool forceReUpload = true) { if (medias == null) { return; } var mediaArray = medias.ToArray(); if (forceReUpload) { mediaArray.ForEach(x => x.UploadedMediaInfo = null); } // Twitter documentation states that an image uploaded on Twitter is retained 60 minutes. // Tweetinvi is republishing a Media after 58 minutes after its first upload. var mediasToPublish = mediaArray.Where(x => !x.HasBeenUploaded || DateTime.Now.Subtract(x.UploadedMediaInfo.CreatedDate).TotalMinutes > 58); foreach (var mediaToPublish in mediasToPublish) { if (mediaToPublish.Data.Length < TweetinviConsts.UPLOAD_MAX_CHUNK_SIZE) { var multipartHttpRequestParameters = new MultipartHttpRequestParameters { Query = Resources.Upload_URL, Binaries = new List <byte[]> { mediaToPublish.Data } }; mediaToPublish.UploadedMediaInfo = _twitterAccessor.ExecuteMultipartQuery <IUploadedMediaInfo>(multipartHttpRequestParameters); } else { var uploadQueryParameters = new UploadQueryParameters { Binaries = new List <byte[]> { mediaToPublish.Data } }; var media = ChunkUploadBinary(uploadQueryParameters); mediaToPublish.UploadedMediaInfo = media.UploadedMediaInfo; } } }
public void UploadMedias(IEnumerable <IMedia> medias, bool forceReUpload = true) { if (medias == null) { return; } var mediaArray = medias.ToArray(); if (forceReUpload) { mediaArray.ForEach(x => x.UploadedMediaInfo = null); } // Twitter documentation states that an image uploaded on Twitter is retained 60 minutes. // Tweetinvi is republishing a Media after 58 minutes after its first upload. var mediasToPublish = mediaArray.Where(x => !x.HasBeenUploaded || DateTime.Now.Subtract(x.UploadedMediaInfo.CreatedDate).TotalMinutes > 58); foreach (var mediaToPublish in mediasToPublish) { var binaries = new[] { mediaToPublish.Data }; mediaToPublish.UploadedMediaInfo = _twitterAccessor.ExecuteMultipartQuery <IUploadedMediaInfo>(Resources.Upload_URL, binaries); } }
// MultiPart Query public static T ExecutePOSTMultipartQuery <T>(string query, IEnumerable <byte[]> binaries, string contentId) where T : class { return(_twitterAccessor.ExecuteMultipartQuery <T>(query, binaries, contentId)); }