无法将文件与其他表单参数一起发布

时间:2016-11-02 11:24:26

标签: java cxf swagger

我正在尝试将一个文件和一些其他参数一起发布到我的REST服务中。我定义了这样的操作:

@POST
@Consumes({MediaType.MULTIPART_FORM_DATA})
@Produces(MediaType.TEXT_PLAIN)
@ApiImplicitParams(@ApiImplicitParam(dataType = "java.io.File", name = "image", paramType = "formData"))
@ApiOperation(value = "Create a car", notes = "Create a new car")
@Path("/new")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Car created in the database"),
        @ApiResponse(code = 500, message = "Car was not created. Error processing the uploaded file")
})
Response createCar(
        @ApiParam(hidden = true, value = "image") List<Attachment> attachments,
        @ApiParam(value = "Token", required = true) @HeaderParam("Token") String token,
        @FormParam(value="model") String model
);

但是,当使用swagger ui发送请求时,服务器中出现异常:

  

java.lang.RuntimeException:无效的URL编码:不是有效数字(基数16): - 17

奇怪的是,如果我删除最后一个参数,一切都很顺利,我收到上传的文件。但是,我在我的方法中需要这个额外的表单参数。

有什么想法吗?

0 个答案:

没有答案