/// <summary>
/// 下载文件
/// </summary>
/// <param name="id">文件ID</param>
/// <returns>返回文件下载链接</returns>
[HttpGet]
[Route("api/Production/FileDownLoad")]
public IHttpActionResult FileDownLoad(string id)
{
var PhysicalPath= GetPhysicalPath(id);
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);
FileStream fileStream = File.OpenRead(PhysicalPath); //文件物理路径
httpResponseMessage.Content = new StreamContent(fileStream);
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = HttpUtility.UrlEncode(Path.GetFileName(OriginalName)) //设置文件名称
};
return ResponseMessage(httpResponseMessage);
}
标签:文件,C#,httpResponseMessage,接口,Content,API,new,id,下载 From: https://www.cnblogs.com/jxw-29/p/17235357.html