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: Upload and download large files

Upload and download large files

Nenciu D.
New member | Level 1

Hello dropboxers,

I'm using Dropbox SDK for .NET v2 and I'm trying to download a file which has 60 MB and I get an AggregateException : {"A task was canceled."} :.I've tried also to download a folder which contains only documents (a few MB) and it works .

The method for download a file:

private async Task GetFileTask(string cloudPath, string localPath)
{
if (string.IsNullOrEmpty(cloudPath) || string.IsNullOrEmpty(localPath))
return;
try
{
var response = await dbxClient.Files.DownloadAsync(cloudPath);
System.IO.Stream responseAsstrin = await response.GetContentAsStreamAsync();
System.IO.FileStream fileStream = System.IO.File.Create(localPath, (int)responseAsstrin.Length);
// Initialize the bytes array with the stream length and then fill it with data
byte[] bytesInStream = new byte[responseAsstrin.Length];
responseAsstrin.Read(bytesInStream, 0, bytesInStream.Length);
// Use write method to write to the file specified above
fileStream.Write(bytesInStream, 0, bytesInStream.Length);
fileStream.Close();
}
catch (AggregateException ex)
{
string message = ex.Message;
}
}

 Also for uploading large files.Same error.

 

Thanks

 

Am I missing something ?

5 Replies 5

Greg-DB
Dropbox Staff

Can you put a breakpoint in your catch block and inspect the exception? It should contain more useful information about the issue from the Dropbox API.

Nenciu D.
New member | Level 1

The type of error is AggregateException.

InnerException : {"A task was canceled."}

Message : One or more errors occurred. 

This is happening at call :

System.Threading.Tasks.Task taskDownloadFile = Task.Run(() => GetFileTask(cloudPath, localPath));
taskDownloadFile.Wait();

Greg-DB
Dropbox Staff

Nenciu D.
New member | Level 1

Thanks Gregory . That was the solution . But I'm having issues when downloading a large file with DownloadAsync

private async Task<Stream> DowloadFileTask(DropboxClient client, string cloudPath, string localPath)
{
IDownloadResponse<FileMetadata> downloadedFileResponse = null;
Stream downloadedFileStream = null;
try
{
downloadedFileResponse = await client.Files.DownloadAsync(cloudPath);
downloadedFileStream = await downloadedFileResponse.GetContentAsStreamAsync();
}
catch (ApiException<DownloadError>)
{ }
return downloadedFileStream == null ? null : downloadedFileStream;
}

I can't see any download method to download chunks of file until all are downloaded. 

Qiming Y.
Dropbox Staff

In the latest version of .NET SDK, you can create DropboxClient using custom http client in which you can specify a longer timeout. See https://github.com/dropbox/dropbox-sdk-dotnet/blob/master/Examples/SimpleTest/Program.cs as example.

Need more support?