how to use multipartfile in spring controller?

I have been trying to send file from rest client to my spring controller. In controller I have used "@requestParam("file") MultipartFile file" to get the file from client and annotated with REST service annotations like below

@Override
    @POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
//  @Path("/FinancePdf")
    @ApiOperation(value = "save finance pdf")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Success",response = String.class),
    })

    public @ResponseBody  String saveFinancePdf(@RequestParam("file") MultipartFile file)
    {
        return "done";
    }

I am always getting 415 Media type not support. in the above method, if I not give the multipart it's giving me the result as done but not with the multipart.

so may I know how to send file from to my spring controller?


尝试使用@FormDataParam并传输文件。

public @ResponseBody String saveFinancePdf(
@FormDataParam("file") InputStream in,
@FormDataParam("file") FormDataContentDisposition fileDisposition ){
     return "done";
}
链接地址: http://www.djcxy.com/p/48738.html

上一篇: 来自InputStream的零文件长度

下一篇: 如何在弹簧控制器中使用multipartfile?