public IMedia ChunkUploadBinary(byte[] binary, string mediaType) { var parameters = new UploadQueryParameters() { Binaries = new List <byte[]> { binary }, MediaType = mediaType, }; return(ChunkUploadBinary(parameters)); }
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; } } }