Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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 ?
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.
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();
I believe this is essentially the same issue as the thread here:
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.
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.
Hi there!
If you need more help you can view your support options (expected response time for a 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!