dropbox-sdk-dotnet icon indicating copy to clipboard operation
dropbox-sdk-dotnet copied to clipboard

Chunky download

Open i1yxa opened this issue 7 years ago • 6 comments

Hi! I've downloading large files. Connection bandwidth is low. I want to implement download recovery after disconnect and continue download. Unfortunetly, I've not found how I can specify offset and size part of requested file review. Can you help me to do it?

i1yxa avatar Oct 04 '18 14:10 i1yxa

The API v2 /2/files/download HTTPS endpoint itself does support "Range Retrieval Requests", but that's unfortunately not currently implemented in the Dropbox .NET SDK. I'll send this along as a feature request for that, but I can't promise if/when that would be implemented in the SDK.

That being the case, you could implement the HTTPS call directly, outside of the SDK, so you can set the desired Range header.

greg-db avatar Oct 04 '18 15:10 greg-db

Hi! Just add the code and it will work:

var uri = "https://content.dropboxapi.com/2/files/download";
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.Headers.Add("Authorization", $"Bearer {_generalCfg.AccessToken}");
request.Headers.Add("Dropbox-API-Arg", $"{{\"path\": \"{_msg.Request.File}\"}}");
request.AddRange(_from, _to);

i1yxa avatar Oct 05 '18 11:10 i1yxa

Better way

                  var uri = "https://content.dropboxapi.com/2/files/download";
                  var request = new HttpRequestMessage(HttpMethod.Post, uri);
                  request.Headers.Authorization = new AuthenticationHeaderValue("Bearer",AccessToken);
                  var encodedPath = EncodeNonAsciiCharacters(file.Path); 
                  var args = $"{{\"path\": \"{encodedPath}\"}}";
                  request.Headers.Add("Dropbox-API-Arg", args);
                 
                  request.Headers.Range =
                  new RangeHeaderValue(_msg.Request.Offset, _msg.Request.Offset + _msg.Request.Length - 1);

                  var response = await httpClient.SendAsync(request, 
                     HttpCompletionOption.ResponseHeadersRead)
                     .ConfigureAwait(false);
                  response.EnsureSuccessStatusCode();

i1yxa avatar Oct 05 '18 14:10 i1yxa

Any progress?

mcdis avatar Nov 14 '18 11:11 mcdis

Hey all, there is no update on this issue to date.

risforrob avatar Nov 14 '18 18:11 risforrob