-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Download link in response body does not work #2132
Comments
After further investigations I could narrow the problem. The downloaded pdf is not empty but some characters have changed and therefore it cannot be shown properly. All the special characters are replaced by '�'. Looks like an encoding problem: Original pdf:
In blob:
|
This is because the xhr.responseType is not blob. This causes the contents of the response are encoded into a UTF-8 string, which cannot be converted back to the original bytes of the response. I don't have a fix, but would be very interested in finding one. |
I have the same problem, if I click to download the file is corrupted , but if you download the file by url from chrome or the file is perfect postman . We may be missing some annotation of swagger ? |
The issue is the xhr.responseType is not blob, so the contents are encoded 2016-07-21 7:34 GMT-04:00 IsmaGitHub notifications@github.com:
|
There is no solution for now? |
No. Take a look at #2282 and 2016-07-21 9:14 GMT-04:00 IsmaGitHub notifications@github.com:
|
@bodnia could you please look at this and see if we can have a generalized solution for the |
@dgreenbean please take a look at 4bdaeba. I believe this addresses this in a general fashion. Leave your feedback on #2404 please |
It won't hurt, but binary -> string is a lossy operation. This means that 2016-09-15 4:11 GMT-04:00 Tony Tam notifications@github.com:
|
Got it, let me look at that. |
ok @dgreenbean fixed in the PR |
I believe that will work as long as the content contains the raw binary 2016-09-15 14:30 GMT-04:00 Tony Tam notifications@github.com:
|
Hi, Taking dist folder is enough for this fix? I see few changes in the src folder as well. |
There was a release, 2.2.6 that incorporates this fix. |
Thanks. I took the 2.2.6 but problem is not gone. I have taken On Thu, Oct 20, 2016 at 8:55 PM, Tony Tam notifications@github.com wrote:
|
No, the dist folder is everything. You only need If the problem is still there, please open a new ticket and share a specification and other details. then we can provide a general fix. |
@ckkiran did you find any solution for this. I am returning file from java code in response, but on download the file get corrupts. While when downloading from browser the URL works fine. Using: Swagger UI 2.2.8 |
@milind-pawar usually this happens when the |
Yes. The problem was with encoding. In swagger-ui.js, there is a function binaryRequest. You need to add your data type there, else by default it will be encoded as unicode/text. Currently, only image and pdf data types are handled. |
@fehguy ok I will show my backend java code also the swagger UI responses i get
On download this file, the file name is this as shown in the below image(which is not the actual file name) also the file gets corrupt. Also when i hit my server URL directly on the browser I get the exact file . |
@milind-pawar. Try what I have suggested. It will resolve your problem - I was facing the same issue. |
@ckkiran thanks for your rply , I found those line of code in swagger-ui.js file, but since I am newbie I don't understand what line of code i need to attach there. :( |
return (/^image/i).test(accept) || (/^application/pdf/).test(accept) || (/^application/octet-stream/).test(accept); |
@ckkiran as I have updated version of swagger-ui.js i.e. 2.2.8, and this code is already in the new js, unfortunately this doesn't work for me :(. |
Look at your request headers. |
Any perfect solution?
|
I think it should have worked if you have taken 2.2.8. Try downloading a text file and see if its corrupted. If its not corrupted then its to do with encoding and the problem will be to do with content type. |
Thanks @ckkiran |
Okay. Then its not encoding problem. There could be lot going wrong. Try different browsers if possible. Check file size after downloading. Vary the file size and check if the file size matches. Open the downloaded text file and see if its completely random or there is some text from your original file. Give a try with application/plain when downloading a text file. This is pretty much I could think of so. Hope it helps. |
I have the same problem, clicking at the download link will download corrupted file. |
I have the same issue. I'm using a controller to grab firmware from the cloud - testing with swagger = EPIC FAIL, Postman = perfect |
Any updates on this issue? I am facing the same |
This issue won't be reopened, as Swagger-UI 2.x is no longer under development. I'm locking this thread to prevent further bumping. If you're experiencing this with the newer 3.x series, please open a new issue 😄 |
I am having a problem similar to the ones described in #374 and #1196. I have a service which returns a pdf file as attachment with
Content-Disposition
header. This works when I call the endpoint from the browser - file is downloaded. On Swagger UI I get a download link after calling the service with response content type application/pdf, however that link downloads an empty pdf file:My
swagger.json
is generated by Enunciate (version 2.3.0) and the relevant part looks like this:I tried adding
"type": "file"
to the schema, but it didn't fix the problem. What could be going wrong here?The text was updated successfully, but these errors were encountered: