如何使用Javascript检索zip文件

时间:2015-10-28 10:55:06

标签: javascript c# asp.net-web-api zip

我的Asp Web Api控制器中有以下代码

public HttpResponseMessage Download(RequestModel model)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            string dataPath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data");
            AttachmentsHelper attachmentsHelper = new AttachmentsHelper(model, dataPath);
            string attachmentsFile = attachmentsHelper.GetAttachments();

            response = Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StreamContent(new FileStream(attachmentsFile, FileMode.Open, FileAccess.Read));
            response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentDisposition.FileName = "photos";
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(MediaTypeNames.Application.Octet);
            return response;
        }

当我通过Ajax请求此方法时,我得到的结果在我的FireBug中看起来很奇怪 Result from web api in FireBug

如何强制浏览器开始下载返回的文件?

0 个答案:

没有答案