I am trying to download a CSV template that only contains one extremely long comma-separated string. My API endpoint is exactly like so:
public HttpResponse DownloadTemplate()
{
var attachment = "attachment; filename=template.csv";
var headers = "Header1,Header2,Header3,HeaderAndSoOnAndSoForth";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
HttpContext.Current.Response.Write(headers);
return HttpContext.Current.Response;
}
This is invoked by a simple AngularJS $http.post
request:
$http.post('api/Files/DownloadTemplate').success(function (data) {
// Do something with data.
});
However, when I'm checking the network response and nothing seems to be returned at all. What am I doing wrong?
(A friend suggested storing the file in the server and just downloading it. Due to a multitude of reasons, I am not allowed to do this.)