Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I want to use the Dropbox. Api for .NET to allow my users to download files I have stores in Dropbox from my site.
The size of the files ranges from small (a few Mb) to Big (a couple of Hundred Mb)
This is the code I have:
public async void DownloadWithTracking(string argFilePath)
{
var aFileName = Path.GetFileName(argFilePath);
using (var aDropboxClient = new DropboxClient(anAccessToken))
{
var aResponse = await aDropboxClient.Files.DownloadAsync(argFilePath);
ulong aFileSize = aResponse.Response.Size;
const int aBufferSize = 4 * 1024 * 1024;
var aBuffer = new byte[aBufferSize];
using (var aDropboxContentStream = await aResponse.GetContentAsStreamAsync())
{
Response.BufferOutput = false;
Response.AddHeader("content-disposition", "attachment;filename=" + aFileName);
Response.AddHeader("Content-Length", aFileSize.ToString());
int aLengthOfBytesRead = aDropboxContentStream.Read(aBuffer, 0, aBufferSize);
while (aLengthOfBytesRead > 0)
{
Response.OutputStream.Write(aBuffer, 0, aLengthOfBytesRead);
aLengthOfBytesRead = aDropboxContentStream.Read(aBuffer, 0, aBufferSize);
}
}
}
}
If the files are small this code works perfectly but for the bigger files I get an error with this stackTrace:
System.IO.IOException was unhandled by user code
HResult=-2146232800
Message=The read operation failed, see inner exception.
Source=System.Net.Http
StackTrace:
at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Http.DelegatingStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at test_DropboxTest.<DownloadWithTracking>d__0.MoveNext() in d:\Dropbox\NPC Website\website\test\DropboxTest.aspx.cs:line 41
InnerException: System.Net.WebException
HResult=-2146233079
Message=The request was aborted: The request was canceled.
Source=System
StackTrace:
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.Read(Byte[] buffer, Int32 offset, Int32 count)
InnerException: This happens after a few 10's of MB (from 20-50 Mb)
Thanks in advance
[Cross-linking for reference: https://stackoverflow.com/questions/43208069/dropbox-net-downloading-large-files-using-getcontentass... ]
I can't seem to reproduce this issue. Is it failing after a certain amount of time? If so, it may be timing out, which would vary by network connection.
Alternatively, are you trying to download multiple files at once? If so, how many?
It's failing after some time... I am downloading a large file, in the case of the test it's a file that's 245 MB.
Downloading this file directly from dropbox took about 6 minutes.
Is there a way to set the time out for a longer period?
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!