4using System.Threading.Tasks;
6using Microsoft.AspNetCore.WebUtilities;
53 Ticket = ticket ??
throw new ArgumentNullException(nameof(ticket));
56 streamTcs =
new TaskCompletionSource<Stream>();
66 return ValueTask.CompletedTask;
70 public async Task<Stream>
GetResult(CancellationToken cancellationToken)
72 using (cancellationToken.Register(() =>
streamTcs.TrySetCanceled(cancellationToken)))
92 public async Task<ErrorMessageResponse>
Completion(
Stream stream, CancellationToken cancellationToken)
94 ArgumentNullException.ThrowIfNull(stream);
99 Stream bufferedStream =
null;
109 await bufferedStream.DrainAsync(cancellationToken);
114 throw new InvalidOperationException($
"Invalid FileUploadStreamKind: {streamKind}");
119 if (bufferedStream !=
null)
120 await bufferedStream.DisposeAsync();
125 await
using (bufferedStream)
127 streamTcs.TrySetResult(bufferedStream ?? stream);
138 throw new InvalidOperationException(
"Error already set!");
142 AdditionalData = additionalData,
Represents an error message returned by the server.
Response for when file transfers are necessary.
IIOManager that resolves paths to Environment.CurrentDirectory.
const int DefaultBufferSize
Default FileStream buffer size used by .NET.
FileTicketResponse Ticket
The FileTicketResponse.
FileUploadProvider(FileTicketResponse ticket, FileUploadStreamKind streamKind)
Initializes a new instance of the FileUploadProvider class.
readonly FileUploadStreamKind streamKind
Determines the backing for the Stream returned from GetResult(CancellationToken).
async Task< ErrorMessageResponse > Completion(Stream stream, CancellationToken cancellationToken)
Resolve the stream for the FileUploadProvider and awaits the upload.
readonly CancellationTokenSource ticketExpiryCts
The CancellationTokenSource for the ticket duration.
ErrorMessageResponse errorMessage
The ErrorMessageResponse that occurred while processing the upload if any.
readonly TaskCompletionSource completionTcs
The TaskCompletionSource that completes in IDisposable.Dispose or when SetError(ErrorCode,...
void SetError(ErrorCode errorCode, string additionalData)
Sets an errorCode that indicates why the consuming operation could not complete. May only be called ...
async Task< Stream > GetResult(CancellationToken cancellationToken)
Gets the provided Stream. May be called multiple times, though cancelling any may cause all calls to ...
readonly TaskCompletionSource< Stream > streamTcs
The TaskCompletionSource<TResult> for the Stream.
void Expire()
Expire the FileUploadProvider.
A FileTicketResponse that waits for a pending upload.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
FileUploadStreamKind
Determines the type of global::System.IO.Stream returned from IFileUploadTicket's created from IFileT...