VivekDev VivekDev - 1 year ago 143
C# Question

Dropbox.Api failing to upload large files

I am uploading files to dropbox using the following code.

I am using the nuget package Dropbox.Api and getting the exception System.Threading.Tasks.TaskCanceledException("A task was canceled.")

From this SO Question it appears to be a timeout issue.

So how do I modify the following code to set the timeout.

public async Task<FileMetadata> UploadFileToDropBox(string fileToUpload, string folder)
DropboxClient client = new DropboxClient(GetAccessToken());

using (var mem = new MemoryStream(File.ReadAllBytes(fileToUpload)))
string filename = Path.GetFileName(fileToUpload);

string megapath = GetFullFolderPath(folder);
string megapathWithFile = Path.Combine(megapath, Path.GetFileName(Path.GetFileName(filename))).Replace("\\", "/");
var updated = client.Files.UploadAsync(megapathWithFile, WriteMode.Overwrite.Instance, body: mem);
await updated;
return updated.Result;
catch (Exception ex)
return null;

Answer Source

Try creating and initializing the client like this:

var config = new DropboxClientConfig();
config.HttpClient.Timeout = new TimeSpan(hr, min, sec); // choose values
var client = DropboxClient(GetAccessToken(), config);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download