private void UploadVideoParts(string videoPath, Models.v5.UploadVideo.Upload upload) { if (!File.Exists(videoPath)) { throw new BadParameterException($"The provided path for a video upload does not appear to be value: {videoPath}"); } var videoInfo = new FileInfo(videoPath); if (videoInfo.Length >= MAX_VIDEO_SIZE) { throw new BadParameterException($"The provided file was too large (larger than 10gb). File size: {videoInfo.Length}"); } const long size24Mb = 25165824; var fileSize = videoInfo.Length; if (fileSize > size24Mb) { // Split file into fragments if file size exceeds maximum fragment size using (var fs = new FileStream(videoPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { var finalChunkSize = fileSize % size24Mb; var parts = (fileSize - finalChunkSize) / size24Mb + 1; for (var currentPart = 1; currentPart <= parts; currentPart++) { byte[] chunk; if (currentPart == parts) { chunk = new byte[finalChunkSize]; fs.Read(chunk, 0, (int)finalChunkSize); } else { chunk = new byte[size24Mb]; fs.Read(chunk, 0, (int)size24Mb); } Api.PutBytes($"{upload.Url}?part={currentPart}&upload_token={upload.Token}", chunk); System.Threading.Thread.Sleep(1000); } } } else { // Upload entire file at once if small enough var file = File.ReadAllBytes(videoPath); Api.PutBytes($"{upload.Url}?part=1&upload_token={upload.Token}", file); } }
private async Task CompleteVideoUploadAsync(Models.v5.UploadVideo.Upload upload, string accessToken) { await Api.TwitchPostAsync(null, ApiVersion.v5, null, accessToken : accessToken, customBase : $"{upload.Url}/complete?upload_token={upload.Token}"); }
private async Task CompleteVideoUpload(Models.v5.UploadVideo.Upload upload, string accessToken) { await Api.PostAsync($"{upload.Url}/complete?upload_token={upload.Token}", null, null, accessToken); }