lundi 25 avril 2016

downloading pdf fil using angular2 and asp.net core

I'm tring to write a WEP API using .net core that return a pdf file my code is :

public HttpResponseMessage GetPdf()
    {
        string fileName = "MY PDF FILE";
        var path = "MY DIRECTORY" + fileName;

        //check the directory for pdf matching the certid

            //if there is a match then return the file
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            var stream = new FileStream(path, FileMode.Open);
            stream.Position = 0;
            result.Content = new StreamContent(stream);
            result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("inline") { FileName = fileName };
            result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
            result.Content.Headers.ContentDisposition.FileName = fileName;
            result.Content.Headers.ContentLength = path.Length;
            result.Content.Headers.Expires = DateTimeOffset.MinValue;


            return result;


    }

when I try to call my function in fiddler I got

HTTP/1.1 200 OK
Date: Mon, 25 Apr 2016 09:47:54 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked

1b9
{"Version":{"Major":1,"Minor":1,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"Content":{"Headers":[{"Key":"Content-Disposition","Value":["inline; filename=StarUML.pdf"]},{"Key":"Content-Type","Value":["application/pdf"]},{"Key":"Content-Length","Value":["48"]},{"Key":"Expires","Value":["Mon, 01 Jan 0001 00:00:00 GMT"]}]},"StatusCode":200,"ReasonPhrase":"OK","Headers":[],"RequestMessage":null,"IsSuccessStatusCode":true}

0

I cannot find the pdf file ?




Aucun commentaire:

Enregistrer un commentaire