这是我的网络 API 代码:
[HttpPost]
public HttpResponseMessage PostFileAsAttachment()
{
string path = "D:\\heroAccent.png";
if (File.Exists(path))
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(path, FileMode.Open);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = "xx.png";
return result;
}
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
以及如何编写客户端(视图)强制下载文件给我(如自动下载模式(打开、另存为)可以弹出...)