Excel file extension save not working in Postman but works in Swagger

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

  1. SSL certificate verification off
  2. “Send and Download” while calling the API
  3. made the call as GET rather POST
  4. 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.

  • 1

    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.

    – 




  • 1

    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.

    – 

  • 1

    That’s a POSTMAN bug. You can’t fix that by changing the header or anything else.

    – 

Leave a Comment