One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
Jack Norton
5 years agoExplorer | Level 3
Files not being downloaded completely
Hi, I am using the following code and noticed that my file is not always downloaded completely. It even optimised with a loop (found online) but this did not solve the problem, can you please help?
using var response = await DropboxClient.AsMember(memberId).Files.DownloadAsync(path).ConfigureAwait(false); fileResponse.ContentType = "application/octet-stream"; using (var stream = await response.GetContentAsStreamAsync().ConfigureAwait(false)) { var bufferSize = 4096; var buffer = new byte[bufferSize]; var readCount = await stream.ReadAsync(buffer, 0, bufferSize).ConfigureAwait(false); while (readCount > 0) { // File is a stream await fileResponse.File.WriteAsync(buffer, 0, readCount).ConfigureAwait(false); readCount = await stream.ReadAsync(buffer, 0, bufferSize).ConfigureAwait(false); } }
- Greg-DB
Dropbox Staff
If you step through with a debugger, where exactly in the code does this stop behaving as expected?
Also, how big is the file you're trying to download, how long does the (incomplete) download take, and that's the final size of the (incomplete) downloaded file?
- Jack NortonExplorer | Level 3
I forgot to mention that it's intermittent and it seems the file is downloaded but, incases of failure, it will be missing an extension. It happens with images 1.5 - 5Mb in size, do you know anything about this?
- Greg-DB
Dropbox Staff
Are you referring to a file extension on fileResponse.File? That would be under your control, not a matter of the Dropbox API/SDK.
For reference, the Dropbox SDK just returns the file data as a stream from GetContentAsStreamAsync(), not file metadata, such as the file name and extension. If you want the file metadata, you can get it from the response object, which in your case would look like 'response.Response'. You can find an example here.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,949 PostsLatest Activity: 7 minutes ago
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 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!