其他分享
首页 > 其他分享> > webapi后端返回文件流

webapi后端返回文件流

作者:互联网

 public HttpResponseMessage GetFileFromWebApi()

 {   try   {   var FilePath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/download/EditPlus64_xp85.com.zip");   var stream = new FileStream(FilePath, FileMode.Open);   HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);   response.Content = new StreamContent(stream);   response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");   response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") {   FileName="Wep Api Demo File.zip"   };   return response;   }   catch   {   return new HttpResponseMessage(HttpStatusCode.NoContent);   }  }

标签:webapi,返回,zip,stream,后端,HttpResponseMessage,Content,new,response
来源: https://www.cnblogs.com/DSC1991/p/15252339.html