Code in use :
[Route("DownloadFile")]
[HttpPost]
public IActionResult DownloadFile(inputdata)
{
try
{
data=//getdata;
if (data)
{
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(data);
using (MemoryStream stream = new MemoryStream())
{
wb.SaveAs(stream);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Excel File.xlsx");
}
}
}
else
return Ok("No data");
}
catch (Exception ex)
{
}
}
This is the controller file (.netcore mvc) . The call works fine and I am able to download the file properly as “Excel File.xlsx” when called from Swagger but in postman it saves the file as “all files” and not with xlsx extension by default.
I tried
- SSL certificate verification off
- “Send and Download” while calling the API
- made the call as GET rather POST
- Accept type as “application/vnd.ms-excel”.
Please help as to how can I save the file by default via postman call as Excel File.xlsx rather just Excel File without any extension.
What’s the actual question? What happens when you actually save the file? Does the extension change? That’s a POSTMAN issue anyway and doesn’t affect browsers or other callers.
postman is not saving the file with any extension. Whatever type is sent in content type or Accept type it simply ignores it and saves as “File” type.
That’s a POSTMAN bug. You can’t fix that by changing the header or anything else.