web api 文件下载
数据源:
1.byte字节流
var stream = new FileStream(filePath, FileMode.OpenOrCreate);
2.本地文件
var stream = new FileStream(filePath, FileMode.OpenOrCreate);
返回类型:HttpResponseMessage
public HttpResponseMessage DownloadExecll(string fundId)
{
var fileName ="";
var bytes = null;
return GetFileResponse(fileName,bytes);
}
private HttpResponseMessage GetFileResponse(string fileName, byte[] bytes)
{
HttpResponseMessage response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
var mime = System.Web.MimeMapping.GetMimeMapping(fileName);
var stream = new MemoryStream(bytes);
response.Content = new StreamContent(stream);
// 下载服务已有的文