Skip to main content

Hello,

I'm trying to download big files in chunks using the API, but no matter how I hit the API, if it's by using de c# SDK or by a plain HTTP Client, always is returning me no more than 3600 bytes per call.

This is not the entire code, but a summarizes what I'm doing. Here I'm trying to download first chunk of 99999 bytes. but It's returning just around 3600.

var config = new BoxConfigBuilder(..);
var session = new OAuthSession(..);
var boxClient = new BoxClient(config, session);
var folderId = 1234;

var items = await boxClient.FoldersManager.GetFolderItemsAsync(folderId, int.MaxValue, fields: new List<string> { "size", "sha1", "name" });
var item = items.First(); //--> Unique 10GB item
var url = await boxClient.FilesManager.GetDownloadUriAsync(item.Id);

using HttpClient client = new HttpClient();
using var boxStream = await client.GetStreamAsync(url);

Memory<byte> buffer = new Memory<byte>(new byte[99999]);
bytesRead = await boxStream.ReadAsync(buffer.ToArray(), 0, buffer.Length);0

//--> bytesRead is sized no more than 3600

 

After some more research I found that configuring the range in http request (range header) works perfectly.
 

var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Range = new System.Net.Http.Headers.RangeHeaderValue(0, ChunkSize);

var response = await client.SendAsync(request);

 


Reply