Last active
May 2, 2016 13:47
-
-
Save davidbreyer/a7922060a39484d3e59341a8388e3bfa to your computer and use it in GitHub Desktop.
Return a PDF to the browser in the form of a byte array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Net; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Web.Http; | |
public class FileServiceController : ApiController | |
{ | |
[Route("api/fileservice/{docId}")] | |
public HttpResponseMessage Get(string docId) | |
{ | |
byte[] response = FileProxy.GetDocumentStream(docId); | |
if (response == null) return new HttpResponseMessage(HttpStatusCode.BadRequest); | |
MemoryStream ms = new MemoryStream(response); | |
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); | |
result.Content = new ByteArrayContent(ms.ToArray()); | |
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment