Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

Nenciu D.'s avatar
Nenciu D.
New member | Level 1
10 years ago

Upload and download large files

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

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    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.'s avatar
    Nenciu D.
    New member | Level 1
    10 years ago

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

  • Nenciu D.'s avatar
    Nenciu D.
    New member | Level 1
    10 years ago

    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. 

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If 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, Facebook or Instagram.

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!