question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Downloaded files have pre/post pended underscores

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ringrahamcommented, Apr 10, 2018

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.

1reaction
heldersepucommented, Apr 9, 2018

Nothing much there but here it is:

      "put": {
        "tags": [
          "Image"
        ],
        "operationId": "Image_Put",
        "consumes": [],
        "produces": [
          "application/octet-stream"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Download an image",
            "schema": {
              "type": "file"
            }
          }
        },
        ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome on Windows adding trailing underscores to ...
The endpoint works fine, but there's something odd happening when the downloaded file reaches the client machine. By the time the browser ...
Read more >
Dot changed to underscore on downloaded files
Hi,. So recently I had a problem with my downloaded files being corrupted. However in the destination that the file was supposed to...
Read more >
REDCap Frequently Asked Questions - Wiki@UCSF
All REDCap data collection instruments can also be downloaded and printed with data entered as a universal PDF file.
Read more >
Why are we seeing copies of files starting with periods and ...
If you see just a few files or folders beginning with a period (.) or period-underscore (._), you can right-click the file/s and...
Read more >
Downloaded filenames are truncated when containing ...
1 When downloading files with underscore characters, filenames are often truncated at the position of the underscore. For example a file called "a_long_movie....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found