我想從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,更新了我的答案。請看一看。 –
我不使用剃刀語法 –