I have a simple question but I'm unable to find a solution for it. Well I have a web api as the server. On the other side I have a xamarin forms client. I read the pdf in a httresponsemessage as a stream and return it to the client.
Here is my web api mvc controller method:
[Route("pdf")]
public HttpResponseMessage GetPDF()
{
//StreamContent pdfContent = PdfGenerator.GeneratePdf();
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new MemoryStream(File.ReadAllBytes(@"D:\TestDocs\Invoice 6134034_27032017152428..pdf")));
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "PDFName.pdf";
return response;
}
In my xamarin app I have this code:
public static HttpResponseMessage DownloadPDF(string token, Uri uri)
{
using (var client = new HttpClient())
{
if (!string.IsNullOrEmpty(token))
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(BEARER, token);
}
return client.GetAsync(uri).Result;
}
}
But now I'm stuck. How can I open this pdf in my xamarin.forms app? I'm using a shared project.
Any help is appreciated.