Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not download with File name which is present in tag"filename" #7577

Open
patelneelj opened this issue Oct 26, 2021 · 3 comments
Open

Does not download with File name which is present in tag"filename" #7577

patelneelj opened this issue Oct 26, 2021 · 3 comments

Comments

@patelneelj
Copy link

patelneelj commented Oct 26, 2021

Versions:
Swagger-UI: 3.25.0
Swagger-Client: 3.10.9
Edge: 95.0
Chrome: 95.0

The same issue was encountered here #1991 and it solved in #1993 in swagger-ui version 2.2.1

However, I am still experiencing the same issue regarding the file name for the octet-stream media type.

Response Header:

content-type: application/pdf
content-disposition: attachment; filename = Category Sales and Profit Performance.pdf 

Code wise:

Response.ok().entity(data).type(MediaType.APPLICATION_OCTET_STREAM_VALUE)
                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename = "+ documentName +".pdf")
                .build();

I have also tried with content-type: application/octet-stream instead of pdf but the same issue.

when I click on "download" from swagger, it is downloading with "application_pdf_pdf_blob_http___nameOftheHost_e64cc118-ce7c-4d7d-b795-288a4dc309c2.pdf" instead of "Category Sales and Profit Performance.pdf"

Note: I also tried with Swagger-UI: 3.52.5. The issue is still present.

I have download the source code and checked, that logic to fetch the name of the file from "fileName" is not present under Swagger-ui/dist/swagger-ui.js

@prolez
Copy link

prolez commented Jan 28, 2022

Same issue with StreamingOutput and application/xml mediaType

Swagger-UI: 4.1.3

Code example:
Response.ok(stream).header("content-disposition", "attachment; filename = " + filename).build()

@gill-ratcu
Copy link

gill-ratcu commented Jul 26, 2023

HttpHeaders headers = new HttpHeaders();
headers.setContentDisposition(ContentDisposition.attachment().filename(fileName).build());

// THIS IS THE MAGIC LINE: ACCESS_CONTROL_EXPOSE_HEADERS

headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);

ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);

@oootkarsh
Copy link

Can confirm. As a consequence of this bug, the swagger-ui-react library is also unable to pick up the content-disposition header's filename (and so the file downloader window doesn't know the correct format of the file to be downloaded).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants