POST a multipartfile

372 views
Skip to first unread message

antxa

unread,
Jan 30, 2017, 6:48:54 AM1/30/17
to Swagger
Hi all,
I've implemented a REST API in Java and one of the POST request accepts a file sent in the body. Everything works OK if I call using this curl:
 curl -F "doc=@file.txt" localhost:8080/index



The problem is that I want to use Swagger for the documentation, and I'm not able to get the same curl through swagger-ui.
This is my snippet code:

@ApiOperation(value = "Index a single document", notes = "...", response = ResultIndex.class)
   
@RequestMapping(value = "/index", method = RequestMethod.POST, consumes={ MediaType.MULTIPART_FORM_DATA_VALUE }, produces = "application/json")
       
@ApiImplicitParams({
 
@ApiImplicitParam(name = "doc", value = "...", required = true, dataType = "file", paramType = "form")})
 
public ResultIndex index(@RequestPart(value="doc", required=true) MultipartFile doc)

And this produces the following curl on the swagger-ui:

curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' {"type":"formData"} 'http://localhost:8080/index'

What's wrong in my code?

Thanks!

tony tam

unread,
Jan 30, 2017, 12:16:13 PM1/30/17
to swagger-sw...@googlegroups.com
This works fine with the core swagger-jaxrs project.  You might need to file an issue on springfox (assuming you’re using that) to see what is wrong with your setup.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

diaz_car...@yahoo.com

unread,
Jan 30, 2017, 2:08:40 PM1/30/17
to swagger-sw...@googlegroups.com

--------------------------------------------
On Mon, 1/30/17, tony tam <feh...@gmail.com> wrote:

Subject: Re: POST a multipartfile
To: swagger-sw...@googlegroups.com
Date: Monday, January 30, 2017, 7:16 PM

This works
fine with the core swagger-jaxrs project.  You might need
to file an issue on springfox (assuming you’re using that)
to see what is wrong with your setup.
On Jan 30, 2017, at 3:48 AM, antxa
<arantz...@ehu.eus>
wrote:
Hi all,I've
implemented a REST API in Java and one of the POST request
accepts a file sent in the body. Everything works OK if I
call using this curl:
 curl
-F
"doc=@file.txt"
localhost:8080/index


The
problem is that I want to use Swagger for the documentation,
and I'm not able to get the same curl through
swagger-ui.This is my
rimele semne ingrijoratoare privind destructurarea statala a Europei centrale si sud-estice sub presiunea Marilor Puteri revizioniste au fost corect receptionate la Bucuresti. Dupa ocuparea Austriei de catre Germania 12 martie 1938 la Bucuresti se luau masuri imperative impotriva organizatiei extremiste de dreapta Garda de Fier iar la 30 aprilie 1938 in contextul declansarii crizei cehoslovace era aprobata survolarea teritoriului romanesc de catre avioanele achizitionate de Cehoslovacia din URSS.
Reply all
Reply to author
Forward
0 new messages