I'm trying to export data from my database to CSV using return File(bytes, contentType, fileName);
This code done based on accepted answer here
I'm expecting a download to start in my browser, but what happens instead, is that the intended contents of the file gets written out to the response body and the response headers have a weird value for content-disposition.
Having updated my response by manually adding a content disposition and sending the return value, I see the content disposition now correctly reads content-disposition: attachment; filename=foo.csv
I'm still not getting my download so I replaced the ;
with a ,
but that didn't help either.
Here's the headers:
content-disposition: attachment, filename=foo.csv
content-encoding: gzip
content-type: text/csv
date: Wed, 21 Apr 2021 06:54:40 GMT
server: Microsoft-IIS/10.0
vary: Accept-Encoding
x-powered-by: ASP.NET
The response does contain the data though...
So the question is how on earth do I get this data output to an actual file that'll be automatically downloaded on the browser?
I'd like to avoid saving files to the server first if at all possible because it's a bit of a nightmare in regard to maintaining.