我创建了一个Web API,可通过OAuth将用户连接到保管箱。 我正在使用API​​与Dropbox进行交互,而Dropbox可以在本地运行,但是将API部署到Azure服务器时,无法下载。 我已经预料到会发生这种情况,因为我的API目前很难适应我机器上的路径。 这是我正在使用的方法:注意: 我通过ActionResult调用此方法,这是我项目的MVC部分的一部分

public FileSystemInfo DownloadFile(string root, string path)
        {
            var uri = new Uri(new Uri(DropboxRestApi.ApiContentServer),
                String.Format("files?root={0}&path={1}",
                root, UpperCaseUrlEncode(path)));

            var oauth = new OAuth();
            var requestUri = oauth.SignRequest(uri, _consumerKey, _consumerSecret, _accessToken);

            var request = (HttpWebRequest) WebRequest.Create(requestUri);
            request.Method = WebRequestMethods.Http.Get;
            var response = request.GetResponse();

            var metadata = response.Headers["x-dropbox-metadata"];
            var file = ParseJson<FileSystemInfo>(metadata);

            using (Stream responseStream = response.GetResponseStream())
            using (MemoryStream memoryStream = new MemoryStream())
            {
                byte[] buffer = new byte[1024];
                int bytesRead;
                do
                {
                    bytesRead = responseStream.Read(buffer, 0, buffer.Length);                    
                    memoryStream.Write(buffer, 0, bytesRead);
                } while (bytesRead > 0);

                file.Data = memoryStream.ToArray();
            }                                    
            return file;                                    
        }

这是我在操作结果中调用该方法的地方。

var file = api.DownloadFile("dropbox", "Public/downloadThis.jpg");
                    path = file.Path;
                    file.Save(@"....\Desktop\DemoTest\Downloads\downloadThis.jpg"); --- this is the problem & *Save* is a stream writer

从浏览器上的服务器下载文件时,有遵循的程序吗?

===============>>#1 票数:0

公共ActionResult下载(Models.downloadModel dowld,Models.LoggerView日志){

        string TC_ID = Request.QueryString["id"].ToString();
        string filename = TC_ID+"_LoggerData" + ".zip";
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
        Response.TransmitFile(Server.MapPath("~/files/" + filename));
        Response.End();

}

  ask by user2254686 translate from so

未解决问题?本站智能推荐: