Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

0ylanmorisson's avatar
0ylanmorisson
Explorer | Level 3
9 years ago
Solved

"A task was canceled" issue when using dropbox chunked upload

 I'm writing a console application that uploads large files to dropbox. I want my program to resume failed upload whenever it accidentally exits or drops connection.  I retrive the uploadID and offset from a txt file to achieve this. 

 

But I constantly get "A task was canceled" issue. And I figured it is a timeout error. I have set "Timeout = TimeSpan.FromMinutes(30)" but it isn't working.

 

So how can I fix this?

 

Below is my code:

 

                try
                {
                    var httpClient = new HttpClient(new WebRequestHandler { ReadWriteTimeout = 10 * 1000 })
                    {
                        // Specify request level timeout which decides maximum time that can be spent on
                        // download/upload files.
                        Timeout = TimeSpan.FromMinutes(30)
                    };
                    var response = await _client.Core.Metadata.ChunkedUploadAsync(fragmentBuffer, count, uploadId, currentPosition, asTeamMember, cancellationToken).ConfigureAwait(false);
                    Console.Write("\r\n2try: {0} of {1} uploaded. uploadId: {2}\r\n", currentPosition, _dataSource.Length, uploadId);
                    uploadId = response.upload_id;
                    var testoffset = response.offset;
                    uploadoffset = testoffset;
                    var testexpires = response.expires;
                    currentPosition = endPosition;
                    Console.Write("\r\n3currentPosition: {0} endPosition: {1} testexpires: {2} count: {3} \r\n", currentPosition, endPosition, testexpires, count);
                }
                //catch (TaskCanceledException ex)
                //{
                //    // Check ex.CancellationToken.IsCancellationRequested here.
                //    // If false, it's pretty safe to assume it was a timeout.
                //    Console.WriteLine("\r\nerr TaskCanceledException: {0}\r\n", ex.CancellationToken.ToString());
                //}     

                catch (Exception e)
                {
                    //write down offset and uploadID to a txt
                    StreamWriter sw = new StreamWriter("1.txt");
                    sw.WriteLine(uploadoffset.ToString());
                    sw.WriteLine(uploadId.ToString());
                    sw.Close();
                    Console.WriteLine("7Err getting response:{0} .. Make sure you have connection again then press enter to resume. \n", e.Message);
                    Console.Write("7catch: currentPosition: {0} endPosition: {1}  \r\n", currentPosition, endPosition);
                    Console.ReadLine();
                }

2 Replies

Replies have been turned off for this discussion

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!