cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

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

0ylanmorisson
Explorer | Level 3
Go to solution

 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();
                }

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Based on your code, it looks like you're using this third party DropboxRestAPI library. Is that correct? If so, unfortunately I'm afraid I can't be of much help, as we can't support third party libraries themselves.

 

Also, it appears that one uses API v1, which is deprecated. You should migrate to API v2. We have an official API v2 .NET SDK that we recommend using. It has an example for uploading large files that you can refer to.

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

Based on your code, it looks like you're using this third party DropboxRestAPI library. Is that correct? If so, unfortunately I'm afraid I can't be of much help, as we can't support third party libraries themselves.

 

Also, it appears that one uses API v1, which is deprecated. You should migrate to API v2. We have an official API v2 .NET SDK that we recommend using. It has an example for uploading large files that you can refer to.

0ylanmorisson
Explorer | Level 3
Go to solution

Thank you, I will check out the new API to see how it works. Thanks!

Need more support?