I am trying to redirect from my MVC application to a FileStreamResult in my web api. The MVC side needs to do a post because of the data that is being sent over. The basic idea is that I should be able to post in the MVC side and what happens next is the API side will create the file and allow me to download/view from there. With what I have it makes the request to the API side but stays on the MVC side. My approximate code is below, any thoughts?
MVC
[HttpGet]
public HttpResponseMessage Download(int id)
{
var body = GetBodyForPost(id);
using (var client = new HttpClient())
{
var response = client.PostAsJsonAsync(url, body);
return response.Result.EnsureSuccessStatusCode();
}
}
API
[HttpPost]
[ActionName("Download")]
public async Task<FileStreamResult> Download([FromBody] IEnumerable<RequestData> data)
{
var stream = BuildFileFromData(data);
Response.Headers.Add("Content-Type", "application/pdf");
Response.Headers.Add("Content-Disposition", "attachment; filename=print.pdf");
return new FileStreamResult(stream, "application/pdf");
}