AspNetCoreCsvImportExport icon indicating copy to clipboard operation
AspNetCoreCsvImportExport copied to clipboard

export data.csv for GET method with query parameters?

Open Phonem1 opened this issue 7 years ago • 3 comments

This works great. I want to pass the query parameters to this get method and export data.csv. Is there a way to do it?

Phonem1 avatar Oct 30 '18 01:10 Phonem1

You will probably have to manually set the response type and stuff. I think it only works right now because the browser sees the .CSV extension

VictorioBerra avatar Oct 30 '18 01:10 VictorioBerra

You would have to implement a normal GET request with parameters and also set the response to the correct media type. Or you could return all responses as a CSV.

damienbod avatar Oct 30 '18 06:10 damienbod

after long search, i decided to use byte streaming instead which works as what i expected. Right now, i don't require to import csv file. [HttpGet] public async Task<IActionResult> Download([FromQuery] LogQueryResource queryResource) { \\ i apply filter, get the data and append to line. byte[] buffer = Encoding.ASCII.GetBytes($"{string.Join(",", ColumnHeaders)}\r\n{data.ToString()}"); return File(buffer, "text/csv", "data.csv"); }

Phonem1 avatar Oct 30 '18 07:10 Phonem1