You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
0ylanmorisson
8 years agoExplorer | Level 3
"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();
}
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.
- Greg-DBDropbox Staff
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.
- 0ylanmorissonExplorer | Level 3
Thank you, I will check out the new API to see how it works. Thanks!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,883 PostsLatest Activity: 4 hours agoIf 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 or Facebook.
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!