Closed sauravpandit closed 6 years ago
I know this tool use swagger ui which is not giving option for file downloading but why when hitting directly from browser is not downloading the file withe name type set in header but running same code from plain express project is working as expected.
@whitlockjc Can you help me on this?
swagger-tools
doesn't remove headers, it might validate a response and throw a 500
but that isn't what's happening. How are you testing this? There is a known issue in swagger-ui
where file downloads don't work.
@whitlockjc Sorry for replying late. I am trying it in two way. First I am accessing it using swagger UI which is integrated with swagger tool and second way is hitting the URL directly in browser. I will focus here on the second way. I am hitting the API URL directly from browser(Chrome, Edge) http://localhost:3000/api/reportweather
In context disposition I have set
'Content-Disposition':'attachment; filename="Book.xlsx"'
Which means it should prompt me to save "Book.xlsx" file but in reality it is downloading a binary response without any extension or file type. I know there is a know issue with swagger UI but I am accessing API using browser. I have run swagger tool in debug mood using VScode. I also have not seen anywhere it is removing any header but I am also not understanding why this issue is happening.
Thank you for replying back.
Hit the API directly from the CLI and see what happens. Do so in verbose mode so I can see the headers sent back.
I have found solution. I have cleared browser cache and tried again. I am getting proper response. @whitlockjc Thank you for providing quick response.
Hi, I was trying to develop an API on top of weather example. I was try create an api which will let user download excel sheet. I have added following api path in existing swagger.json
I have added the following code in Weather.js file
Now when I am trying to access the api using Swagger UI built in withing application, instead of file I am getting some binary data. Most surprisingly I am not seeing the header which I have set in Node js code.
If I hit the url directly (http://localhost:3000/api/reportweather) from browser the file is getting downloaded but it is taking the name from url without any extension(Just reportweather). It is not downloading the file as set using "Content-Disposition".
If I create a plain express project and use the code
The file is getting download as expected. It is following the instruction given in 'Content-Disposition' header.
'Content-Disposition':'attachment; filename="Book.xlsx"'
I am not understanding why this header is getting deleted from response. It will great if anyone help me on this.