public async Task <BackblazeApiResponse <UploadedPartOutputDTO> > UploadLargeFilePartAsync( AuthorizationOutputDTO auth, FileDataOutputDTO fileData, Stream partStream, int partNumber, int retryTimeoutCount = 5, IProgress <FilePartProgress> progressData = null, CancellationToken cancellationToken = default(CancellationToken) ) { if (partStream == null) { throw new NullReferenceException("partStream"); } if (!partStream.CanRead) { throw new InvalidDataException(); } int retryCount = 0; Retry: var uploadUrlResponse = await GetUploadPartUrlAsync(auth, fileData, cancellationToken); if (!uploadUrlResponse.Succeeded) { return(new BackblazeApiResponse <UploadedPartOutputDTO>() { Succeeded = uploadUrlResponse.Succeeded, Error = uploadUrlResponse.Error }); } UploadedPartOutputDTO uploadPart = null; var uploadPartResponse = await UploadLargeFilePartAsync(uploadUrlResponse.Data, partStream, fileData.FileName, partNumber, progressData, cancellationToken); if (uploadPartResponse.Succeeded) { uploadPart = uploadPartResponse.Data; } else { if (ErrorHelper.IsRecoverableError(uploadPartResponse.Error)) { if (retryCount > retryTimeoutCount) { uploadPartResponse.Error.Message = $"Hit retry max on error: {uploadPartResponse.Error.Message}"; return(new BackblazeApiResponse <UploadedPartOutputDTO>() { Succeeded = false, Error = uploadPartResponse.Error }); } retryCount++; goto Retry; } else { return(new BackblazeApiResponse <UploadedPartOutputDTO>() { Succeeded = false, Error = uploadPartResponse.Error }); } } return(new BackblazeApiResponse <UploadedPartOutputDTO>() { Succeeded = uploadUrlResponse.Succeeded, Data = uploadPart }); }
/// <summary> /// Upload a file with attempted recovery from errors /// </summary> public async Task <BackblazeApiResponse <FileDataOutputDTO> > UploadSmallFileAsync( AuthorizationOutputDTO auth, string bucketId, string sourcePath, string destinationFilename, int retryTimeoutCount = 5, IProgress <FileProgress> progressData = null, CancellationToken cancellationToken = default(CancellationToken) ) { int retryCount = 0; Retry: var uploadUrlResponse = await GetUploadUrlAsync(auth, bucketId, cancellationToken); if (!uploadUrlResponse.Succeeded) { return(new BackblazeApiResponse <FileDataOutputDTO>() { Succeeded = uploadUrlResponse.Succeeded, Error = uploadUrlResponse.Error }); } FileDataOutputDTO uploadData = null; var uploadDataResponse = await UploadSmallFileAsync(uploadUrlResponse.Data, sourcePath, destinationFilename, progressData, cancellationToken); if (uploadDataResponse.Succeeded) { uploadData = uploadDataResponse.Data; } else { if (ErrorHelper.IsRecoverableError(uploadDataResponse.Error)) { if (retryCount > retryTimeoutCount) { uploadDataResponse.Error.Message = $"Hit retry max on error: {uploadDataResponse.Error.Message}"; return(new BackblazeApiResponse <FileDataOutputDTO>() { Succeeded = false, Error = uploadDataResponse.Error }); } retryCount++; goto Retry; } else { return(new BackblazeApiResponse <FileDataOutputDTO>() { Succeeded = false, Error = uploadDataResponse.Error }); } } return(new BackblazeApiResponse <FileDataOutputDTO>() { Succeeded = uploadDataResponse.Succeeded, Data = uploadData }); }