Abd Abd - 1 year ago 432
C# Question

c# Dropbox RestSharp download file to stream

I have an 'ASP.NET' console application and I use 'RestSharp' client for Dropbox.

I use this code to download a file :

var baseUrl = "https://content.dropboxapi.com";

var client = new RestClient(baseUrl);
client.Authenticator = OAuth1Authenticator.ForRequestToken(mc_apiKey, mc_appsecret);

RestRequest request = new RestRequest(string.Format("/{0}/files/auto", mc_version), Method.GET);

client.Authenticator = OAuth1Authenticator.ForProtectedResource(mc_apiKey, mc_appsecret, accessToken.Token, accessToken.Secret);
request.AddParameter("path", path);

var responseAccount = client.Execute(request);
var fileString = responseAccount.Content;
byte[] b1 = System.Text.Encoding.UTF8.GetBytes (fileString);

When call
the whole file is loaded in memory, so when I have a very largefile in Dropbox the program will crash.

I need to get the file to stream without using
to download to local storage.

I need to be able to stream the file in chunks.

Abd Abd
Answer Source

I found the best answer in link:

 string url = String.Format("https://content.dropboxapi.com/1/files/auto{0}?oauth_consumer_key={1}&oauth_token={2}&oauth_signature={3}%26{4}", path, app-key, access-token, app-secret, access-token-secret);
 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
 webRequest.Method = "Get";
 WebResponse webResponse = null;
     webResponse = webRequest.GetResponse();
     return webResponse.GetResponseStream();
  catch (Exception ex)
    throw ex;       
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download