Exemplo n.º 1
0
 public bool Append(byte[] binary, string mediaType, TimeSpan? timeout = null, int? segmentIndex = null)
 {
     var parameters = new ChunkUploadAppendParameters(binary, mediaType, timeout);
     parameters.SegmentIndex = segmentIndex;
     return Append(parameters);
 }
Exemplo n.º 2
0
        public IMedia ChunkUploadBinary(IUploadQueryParameters uploadQueryParameters)
        {
            if (uploadQueryParameters.Binaries.Count != 1)
            {
                throw new ArgumentException("ChunkUpload binary can only upload 1 binary at a time.");
            }

            var binary = uploadQueryParameters.Binaries[0];
            var uploader = CreateChunkedUploader();

            var initParameters = new ChunkUploadInitParameters
            {
                TotalBinaryLength = binary.Length,
                MediaType = uploadQueryParameters.MediaType,
                AdditionalOwnerIds = uploadQueryParameters.AdditionalOwnerIds,
                CustomRequestParameters = uploadQueryParameters.InitCustomRequestParameters,
            };

            if (uploader.Init(initParameters))
            {
                var binaryChunks = GetBinaryChunks(binary, uploadQueryParameters.MaxChunkSize);

                var totalsize = 0;

                foreach (var binaryChunk in binaryChunks)
                {
                    totalsize += binaryChunk.Length;
                    var appendParameters = new ChunkUploadAppendParameters(
                        binaryChunk, 
                        "media", // Must be media, if using the real media type as content id, Twitter does not accept when invoking .Finalize().
                        uploadQueryParameters.Timeout);

                    appendParameters.CustomRequestParameters = uploadQueryParameters.AppendCustomRequestParameters;

                    if (!uploader.Append(appendParameters))
                    {
                        return null;
                    }
                }

                var isTrue = totalsize == binary.Length;

                return uploader.Complete();
            }

            return null;
        }