/// <summary> /// Uploads a large file in chunked parts. /// </summary> /// <param name="request">The <see cref="UploadFileRequest"/> content to send.</param> /// <param name="progress">A progress action which fires every time the write buffer is cycled.</param> /// <param name="cancellationToken">The cancellation token to cancel operation.</param> private async Task <IApiResults <UploadFileResponse> > UploadLargeFileAsync (UploadLargeFileRequest request, IProgress <ICopyProgress> progress, CancellationToken cancellationToken) { if (request.ContentLength < ClientOptions.MinimumPartSize) { throw new ArgumentOutOfRangeException($"Argument must be a minimum of {ClientOptions.MinimumPartSize} bytes long.", nameof(request.ContentLength)); } List <string> sha1Hash = new List <string>(); var parts = GetStreamParts(request.ContentStream, Options.UploadPartSize); if (parts.Count == 0) { throw new ApiException($"The number of large file parts could not be determined from stream."); } var fileRequest = new StartLargeFileRequest(request.BucketId, request.FileName) { ContentType = request.ContentType, FileInfo = request.FileInfo }; fileRequest.FileInfo.SetLargeFileSha1(request.ContentStream.ToSha1()); var fileResults = await StartLargeFileAsync(fileRequest, cancellationToken).ConfigureAwait(false); if (fileResults.IsSuccessStatusCode) { var urlRequest = new GetUploadPartUrlRequest(fileResults.Response.FileId); var urlResults = await GetUploadPartUrlAsync(urlRequest, default, cancellationToken).ConfigureAwait(false);
/// <summary> /// Gets a url for uploading parts of a large file. /// </summary> /// <param name="fileId">The large file id whose parts you want to upload.</param> /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception> /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception> async Task <IApiResults <GetUploadPartUrlResponse> > IStorageParts.GetUploadUrlAsync(string fileId) { var request = new GetUploadPartUrlRequest(fileId); return(await _client.GetUploadPartUrlAsync(request, _cancellationToken)); }