How to solve the problem of file download garbled and Knife4j.txt in swagger-bootstrap-ui upgrade Knife4j
This article is about how to solve the swagger-bootstrap-ui upgrade Knife4j file download garbled and Knife4j.txt problems. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
I. preparation for upgrading Knife4j
Dependency introduction
Com.github.xiaoymin knife4j-spring-boot-starter
Annotations open
@ EnableSwagger2@EnableKnife4jpublic class SwaggerAutoConfiguration {/ /.} 2. File download API
Download garbled problem
The garbled code problem occurs because Knife4j does not support @ PostMapping file cache, so you need to convert the interface to GetMapping.
Download the file as Knife4j.txt
The file stream is empty
Configure produces = MediaType.APPLICATION_OCTET_STREAM_VALUE for GetMapping
Set the response header (note spaces and commas)
Response.setHeader ("Content-Disposition", "attachment;filename=" + URLEncoder.encode (fileName, "utf-8"))
Get request does not support request parameter cache, and it is very inconvenient to reset the parameters every time a file is downloaded.
Post request is not supported for file download
If the returned data is too large, the page will be very stuck. It is not recommended to upgrade knife4j.
Thank you for reading! On "how to solve swagger-bootstrap-ui upgrade Knife4j file download garbled and Knife4j.txt problems" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!