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); }
/// <summary> /// Upload a binary using the chunked upload mechanism. /// </summary> public static IMedia ChunkUploadBinary(IUploadQueryParameters parameters) { return UploadQueryExecutor.ChunkUploadBinary(parameters); }
/// <summary> /// Upload a binary using the chunked upload mechanism. /// </summary> public static IMedia ChunkUploadBinary(IUploadQueryParameters parameters) { return(UploadQueryExecutor.ChunkUploadBinary(parameters)); }
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; }