How to send filesteam to browser in blazor app

Viewed 62

I need to call a web api that returns a pdf. I want to display that pdf when the user clicks a download button. Here's my code. Nothing seems to happen when the button is clicked although through debug I can see the successful download of the file from the api and writing to local disk. I'd prefer to send the file straight to the browser instead of downloading. Here is what I've tried.

On the page button @onclick="@(e => Download_doc())">Download

In my .cs var request = new HttpRequestMessage(HttpMethod.Get, "URL"); HttpResponseMessage resp = await client.SendAsync(request);

        var file = System.IO.File.Create("download.pdf");
        var content = await resp.Content.ReadAsStreamAsync();
        await content.CopyToAsync(file);
        Console.Write(file);
        return file;

Any suggestions would be appreciated.

0 Answers
Related