public byte[] DownloadDocument([FromBody] DownloadDoc doc) { IPolicyService policyService = new PolicyService(); //DocID="EHSDOC-4-1" byte[] fileBytes; if (doc != null) { var stream = policyService.DownloadDocument(doc.Name, doc.Path); HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); byte[] buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { stream.CopyTo(ms); fileBytes = ms.GetBuffer(); // response.Content.Headers.ContentLength = ms.Length; } return(fileBytes); } else { return(null); } }
public HttpResponseMessage DownloadFile([FromBody] DownloadDoc doc) { //byte[] fileBytes = null; IPolicyService policyService = new PolicyService(); Stream stream = null; if (doc != null) { stream = policyService.DownloadDocument(doc.Name, doc.Path); } else { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); byte[] buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { stream.CopyTo(ms); response.Content = new ByteArrayContent(ms.GetBuffer()); response.Content.Headers.ContentLength = ms.Length; } response.Headers.AcceptRanges.Add("bytes"); response.StatusCode = HttpStatusCode.OK; response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); //response.Content.Headers.ContentLength = stream.Length; //response.Content.Headers.ContentLength = contentInfo.Length; response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); //response.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/pdf"); response.Content.Headers.ContentDisposition.FileName = doc.Name; return(response); }