0

我创建了一个 web api,它通过 OAuth 将用户连接到 Dropbox。我正在使用 API 与 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

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

4

1 回答 1

0

公共 ActionResult 下载(Models.downloadModel 下载,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();

}

于 2013-05-10T06:02:50.463 回答