Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
pear0533
3 years agoExplorer | Level 3
Dropbox API Hangs During Large File Download
Hey there! I am currently maintaining a mod launcher software that utilizes the Dropbox .NET C# API to allow users to download mod files.
Unfortunately, large files (usually 2-5GB in size) do n...
Greg-DB
Dropbox Community Moderator
3 years agoI see the agent in the support ticket you referred to supplied this example:
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://content.dropboxapi.com/2/files/download");
request.Headers.Add("Authorization", "Bearer " + accessToken);
request.Headers.Add("Dropbox-API-Arg", "{\"path\":\"/test.txt\"}"); // in real code, use a JSON library to build this
request.Headers.Add("Range", "bytes=0-10"); // this requests the first 11 bytes of the file
HttpResponseMessage response = await client.SendAsync(request);
Stream stream = response.Content.ReadAsStream(); // read from stream as desired
That looks correct; the only additional thing you need to do to a /2/files/download call to request a specific range is add the "Range" header like that.
Здравко
3 years agoLegendary | Level 20
Greg-DB wrote:...
... request.Headers.Add("Range", "bytes=0-10"); // this requests the first 11 bytes of the file
......
Hi pear0533,
You don't actually need a range starting from zero. You can start with regular API call and if that breaks for some reason then go forward with range(s).
Let's say you have to download a file and start downloading it in regular way. At some moment transfer breaks, let say, at position 50 byte. Since headers are available, you know that the file is, let say, 200 bytes. So, you have downloaded 50 bytes already and there are some more to read. The easiest way is to set range to something like:
request.Headers.Add("Range", "bytes=50-");I.e. you're starting from byte 51 and onward. Now, let's say you got another 70 bytes successfully. Together with the first 50 bytes they form successfully downloaded block of 120 bytes. You can continue with:
request.Headers.Add("Range", "bytes=120-");I.e. you're starting again, but from byte 121 and onward. There is a big chance your download to complete successful. 😉 If not, continue the same logic further.
Hope this gives direction.
- Greg-DB3 years ago
Dropbox Community Moderator
Thanks for the helpful added explanation Здравко!
pear0533 For reference, you can find more information on how to set ranges in the specification here. Note that Dropbox does not support setting multiple ranges in a single request though. That is, you can specify a single closed range like "bytes=0-10", or a single open range like "bytes=50-", but you can't specify multiple ranges at once like "bytes=0-999,4500-5499".
Hope this helps!
- pear05333 years agoExplorer | Level 3
I see now, yeah, that should help. The only concern that I have is that even while using range requests previously, I do not understand why eventually I was no longer able to perform any more range requests. Hopefully this isn't the case this time... thanks!
About 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!