0

We are using the Box oAuth Api in our application to download and upload files in to our Box.com account. I am able to succeed to download and upload files up to 200 MB Size. But when try to download the files with the size 3.5 GB, then the Application is not responding and it's occupying the most of the RAM usage (2,741,900).

I pulled the file down myself manually, which took about 15 minutes, removed it from Box, and restarted my download service. The code then chewed through all of the piled up files that were on Box without an issue. Although, I think the resting state utilization of memory is still kind of high (115MB), it is better.

Any idea why memory is being consumed when copying files down.

Is that something we can look at it?

Please help me on this.

Thanks in advance for your time.

Thanks & Regards, Satish.Neelakantam

Satish
  • 1
  • 3
  • Can you provide a code sample that reproduces the issue? – John Hoerr Jul 08 '13 at 14:11
  • var downloadUrl = "https://api.box.com"; RestClient downloadClient = new RestClient(downloadUrl); RestRequest downloadrequest = new RestRequest(string.Format("/{0}/files/{1}/content", mc_version, fileID), Method.GET); downloadrequest.AddParameter("Authorization",string.Format("Bearer {0}", accessToken), ParameterType.HttpHeader); var fileContent = downloadClient.Execute(downloadrequest); if (fileContent.StatusCode.ToString() == "OK") {_rtn = DownloadFileFromBox(fileContent.ResponseUri.ToString(), fileName, tmpFileLocation); } – Satish Jul 08 '13 at 14:55
  • **DownloadFileFromBox Method:** var dir = tmpFileLocation; // folder location localFile = dir + "\\" + localFile; if (!Directory.Exists(dir)) // if it doesn't exist, create Directory.CreateDirectory(dir); //create an instance of WebClient - the heart of downloading a file WebClient fileReader = new WebClient(); //check if the file already exists locally if (!(File.Exists(localFile))) { fileReader.DownloadFile(fileToDownload, localFile); _result = true; } else { File.Delete(localFile); fileReader.DownloadFile(fileToDownload, localFile); _result = true; } – Satish Jul 08 '13 at 14:56

1 Answers1

2

The problem is with WebClient.DownloadFile, not with the Box API. Consider switching to a stream-based solution.

EDIT

In addition to working with streams, you may also consider that a request to files/ID/content will always result in a 302 Found redirect to a particular download URL. This URL will accept a Range header, with which you can specify a particular byte range to fetch. This makes it possible to resume failed downloads. Be aware that the download URL is not static, so you should call files/ID/content prior to each Range read operation to ensure that your download URL is valid.

Community
  • 1
  • 1
John Hoerr
  • 7,955
  • 2
  • 30
  • 40
  • Hi John, Thanks for the response. I have used the method (MyDownloadFile) which they have specified in the above Stream-Based Solution link instead of WebClient.DownloadFile() method. Even though it's occupying the more memory (5,19,620 KB of Memory). And finally I am getting the message like Unable to Download the file. Please help is required on this. Thanks in advance for your time. – Satish Jul 09 '13 at 06:44
  • var downloadUrl = "https://api.box.com"; RestClient downloadClient = new RestClient(downloadUrl); RestRequest downloadrequest = new RestRequest(string.Format("/{0}/files/{1}/content", mc_version, fileID), Method.GET); downloadrequest.AddParameter("Authorization",string.Format("Bearer {0}", accessToken), ParameterType.HttpHeader); var fileContent = downloadClient.Execute(downloadrequest); – Satish Jul 10 '13 at 07:44
  • From the above code we are not getting the response from the Box if the file size is more than MB’s like if the file size is in GB’s then the response is not coming and finally it’s throwing (Exception of type 'System.OutOfMemoryException' was thrown). Please let me know u r email_id. So, that I can send you the screenshots for your reference. – Satish Jul 10 '13 at 07:44