将应用程序/八位字节流从IE9中的javascript保存到磁盘
我在WebApi上提供了下载文件的方法:将应用程序/八位字节流从IE9中的javascript保存到磁盘,javascript,file,stream,internet-explorer-9,savefiledialog,Javascript,File,Stream,Internet Explorer 9,Savefiledialog,我在WebApi上提供了下载文件的方法: public HttpResponseMessage Get(int id) { MemoryStream file = RetrieveFile(id); if (file != null) { var response = new HttpResponseMessage(HttpStatusCode.OK);
public HttpResponseMessage Get(int id)
{
MemoryStream file = RetrieveFile(id);
if (file != null)
{
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(file);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "dummy.txt"
};
return response;
}
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
这工作正常,我可以使用WebClient使用它
我还使用FileSaver.js实现了javascript前端:
$http({
url: myUrl,
method: 'GET',
params: {
id: 1
},
headers: {
'Content-type': 'application/json'
}
}).success(function (data, status, headers, config) {
var file = new Blob([data], {
type: 'application/octet-stream'
});
saveAs(file, "test.txt");
}).error(function (data, status, headers, config) {
});
这非常有效,但在IE9上失败,因为不支持FileSaver和Blop。
我尝试在一个新窗口中打开url,但找不到一个合适的IE9解决方案你有什么收获吗?@RichardMc没有,不可能