AmazonCloudDriveApi
AmazonCloudDriveApi copied to clipboard
How to cancel file upload?
I see this:
public async Task<R> SendFile<R>(HttpMethod method, string url, FileUpload file)
{
// ... [skipped] ...
await pre.CopyToAsync(output).ConfigureAwait(false);
await input.CopyToAsync(output).ConfigureAwait(false);
await post.CopyToAsync(output).ConfigureAwait(false);
// ... [skipped] ...
}
But this does not allow to cancel the upload action. CopyToAsync can accept a CancellationToken, but it's not passed. Can we have it fixed, please?
Also, is there a way to monitor the progress?
I pushed update with new UploadNew and updated Overwrite CopyToAsync throws TaskCanceledException , but it's subclass of OperationCanceledException.
Upload progress will be later it's 3am
Thank you for your efforts! Will be waiting for the progress support.
I'm not sure, how you are going to implement the progress support, but one of possible ways could be replacing CopyToAsync by a custom solution similar to what can be seen here: https://psycodedeveloper.wordpress.com/2013/04/04/reliably-asynchronously-reading-and-writing-binary-streams-in-c-always-check-method-call-return-values/ (the final variant)
Playing around I discovered two issues:
- If we use CopyToAsync(), it takes too much time to react on cancel request.
- The most annoying problem is that when you cancel the request, the socket is not closed (and not reused). And thus, the next call will create a new one in addition, and so on. Eventually, the app will be blocked because we didn't close cancelled sockets. I had to check the token's
IsCancellationRequested
manually and callclient.abort()
to close the socket. You can check the changes in my fork: https://github.com/denisvmedia/AmazonCloudDriveApi/blob/master/AmazonCloudDriveApi/HttpClient.cs