Open dheerajuppalapati opened 7 years ago
Swagger-ui does not support multipart file upload
I'm guessing this is not the right place to ask questions about springfox?? Every-time I ask questions I get answers from you which do not make sense.
What does this mean "Swagger-ui does not support multipart file upload"?? Springfox is build on swagger and example you posted for sprinfox here https://github.com/springfox/springfox-demos/blob/be4118bb031c8dcded514c33d74cae52fc51ff08/boot-swagger/src/main/java/springfoxdemo/boot/swagger/web/FileUploadController.java is for Multipart file upload.
I asked a simple question and I keep getting ridiculous answer.
I am also facing similar problem with https://github.com/springfox/springfox-demos/blob/be4118bb031c8dcded514c33d74cae52fc51ff08/boot-swagger/src/main/java/springfoxdemo/boot/swagger/web/FileUploadController.java
When I modify @RequestPart String description
to @RequestPart RequestObject requestObject
I am getting error
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported
Even the curl generated by swagger-ui produces same error, but once I add type=application/json to body problem is fixed curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' -F 'requestObject=@/req.json;type=application/json' 'http://localhost:8080/MyService/api/upload'
looking at https://github.com/swagger-api/swagger-core/issues/636, it looks like swagger-ui have support to provide content-type for RequestPart.
springfox version 2.7.0 springboot Version 1.5.4.RELEASE
Request parts, and multipart requests in general are not supported by swagger-ui. Atleast as of version 2.0 of the spec.
Hi Dilip, I am confused here, isn't FileUploadController.java multipart request with two request parts ?
It is but swagger-ui and OpenAPI spec in general doesnt support multipart requests well. FileUploadController
is just to demonstrate that springfox tries to generate the right description
Thanks Dilip
FileUploadController.java actually works, but its just that when we change @RequestPart String description
to @RequestPart RequestObject requestObject
it produces following error org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported
so does this means that it is partially supported?
Dilip / Nitesh, any update on this issue. I'm also facing the same issue. When i change @RequestPart String to @RequestPart Object, i'm getting the error.
Multipart requests are not supported very well in Swagger-ui unfortunately
"Multipart requests are not supported very well in Swagger-ui unfortunately" then for file upload instead of multipart file which data type can we use?
I tried the example https://github.com/springfox/springfox-demos/blob/be4118bb031c8dcded514c33d74cae52fc51ff08/boot-swagger/src/main/java/springfoxdemo/boot/swagger/web/FileUploadController.java
Just changed the @RequestPart String description to @RequestBody Component component which should be a JSON input.
Here is the code sample @RequestMapping(value = "/v1/component/fileupload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public Component fileComplaint( @RequestBody Component component, @RequestPart MultipartFile file){ ........................... }
Here is what the swagger-ui looks like
Here is the request details
Here is the response details
Here are my questions:
I'm not sure why does say in swagger-ui. It should say "application/json" instead. How do i fix this?
If you request at the request paramaters, the data i'm putting in the "component" parameter is not being sent to the back-end. It only sends the file details.
How do i fix org.springframework.web.HttpMediaTypeNotSupportedException??
Any kind of help will be appreciated. I already checked out the suggestions in https://github.com/springfox/springfox/issues/134 and it was of no help
Thanks, Dheeraj