C#Dropbox RestSharp下载文件以流式传输 [英] c# Dropbox RestSharp download file to stream

查看:723
本文介绍了C#Dropbox RestSharp下载文件以流式传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个'ASP.NET'控制台应用程序,并且我将'RestSharp'客户端用于Dropbox。

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);

在调用 client.Execute(request)时整个文件都加载到内存中,所以当我在Dropbox中有一个非常大的文件时,程序将崩溃。

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

我需要在不使用<$ c的情况下使文件流式传输$ c> client.DownloadData(request).SaveAs(path)以下载到本地存储。

I need to get the file to stream without using client.DownloadData(request).SaveAs(path) to download to local storage.

我需要能够流式传输

推荐答案

我在链接

 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;
  try
  {
     webResponse = webRequest.GetResponse();
     return webResponse.GetResponseStream();
  }
  catch (Exception ex)
  {
    throw ex;       
  }

这篇关于C#Dropbox RestSharp下载文件以流式传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆