我想从asp.net web api下载文件(.docx)。从asp.net web api下载文件
因为我已经有服务器中的文件我将路径设置为现有的一个,然后我按照一些sugested计算器上做此:
docDestination是我的道路。
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(docDestination, FileMode.Open, FileAccess.Read);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
return result;
后,关于我的客户端我试着这样做:
.then(response => {
console.log("here lives the response:", response);
var headers = response.headers;
var blob = new Blob([response.body], { type: headers['application/vnd.openxmlformats-officedocument.wordprocessingml.document'] });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = "Filename";
link.click();
}
这是我得到我的回应
我得到:
有帮助吗?
我怎样才能得到它在客户端? –
@FilipeCosta,更新了我的答案。请看一看。 –
我不使用剃刀语法 –