Downloaded files have pre/post pended underscores
See original GitHub issueWhen downloading files, the UI seems to pre and post pend underscores to the filename.
Version: Swagger 2.0 UI
Q: For example, the service returns “File01.zip”. On the browser side, it downloads as “File01.zip”. I’m running both a pretty old version of swagger that doesn’t add the underscores and trying to upgrade to Swagger 2.0 both API and UI. To install the UI, I simply copied the dist folder contents to our tomcat server. Server is running RHEL 7.0 with Tomcat 7.
My yaml code for this services:
'/export/download/{id}':
get:
tags:
- "export:"
summary: Download a zip file containing document with given ID
description: Zip file to be downloaded with the given document ID
produces:
- application/zip
parameters:
- $ref: '#/parameters/uuidParam'
responses:
'200':
description: "CSV Zipped File"
schema:
"type": "file"
'400':
$ref: "#/responses/InvalidParam"
'500':
$ref: "#/responses/ServerError"
The returned Response Headers are:
access-control-allow-headers: Content-Type
access-control-allow-methods: GET, POST, DELETE, PUT
access-control-allow-origin: *
content-disposition: attachment; filename="File01.zip"
content-length: {len of the file}
content-type: application/octet-stream
date: DDD, dd mmm YYYY hh:mm:ss GMT
server: Apache-Coyote/1.1
I was really surprised that this issue has not come up before and am wondering if I am doing something pretty obvious that is causing this, but I have gone over this for hours now and do not see how the underscores are being added?? Note that the older version of Swagger we are using doesn’t have this issue.
It took me quite a few hours to figure out that, without the content-length, the file was not even downloading, though I could see the byte stream coming across. This one I am stumped on. Thanks to anyone who takes the time to look at this.
Issue Analytics
- State:
- Created 5 years ago
- Comments:18 (8 by maintainers)

Top Related StackOverflow Question
Fixed! Found out it was the Content-Disposition header that was being returned. The service is for a set of Java REST services and the docs indicated the file should be returned as: response.header(“Content-Disposition”, “attachment; filename="” + zip.getName() + “"”); (Note that when I write this the code is actually escaping a double-quote (slash following by a double-quote, inside double-quotes) but it doesn’t seem to display this correctly. They are appearing as double and triple quotes!?)
This would put quotes around the returned filename. I removed these, so the line becomes: response.header(“Content-Disposition”, “attachment; filename=” + zip.getName() + ");
And the filename now downloads without the pre|postpended underscores. Thanks Helder for all your help. Even though the fix was in the java REST service and not in Swagger, I thought you might like to know in case this issue ever comes up again.
Nothing much there but here it is: