This is the code in my Web API 2 controller:
//pdfBytes is a valid set of...pdfBytes, how it's generated is irrelevant
Byte[] pdfBytes = pdfConverter.GeneratePdf(myPdfString);
//using HttpResponseMessage instead of IHttpActionResult here because I read
//that the latter can cause problems in this scenario
var response = new HttpResponseMessage();
//Set reponse content to my PDF bytes
response.Content = new ByteArrayContent(pdfBytes);
//Specify content type as PDF - not sure if this is necessary
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return response;
How do I trigger the browser to automatically download the PDF or open it in a new window once I have received the PDF on the client? (Note - I am not sure if byte array is the format I want to receive here).
callToGetPdfFromDb()
.success(function (pdfFromWebApi) {
console.log('Got pdf...'');
//How do I show the received PDF to the user?
});
I am pretty new to working with any sort of file downloads/uploads, so I apologize if I am missing something very basic. I am perfectly happy with pointers in the right direction as a response.