Consuming a multipart/form-data via RESTful CXF

后端 未结 3 470
再見小時候
再見小時候 2021-01-05 04:59

I\'ve been working in a webservice that consumes and produces JSON files using Apache CXF in conjuction with Jackson.
However, one of the service\'s methods should be

相关标签:
3条回答
  • 2021-01-05 05:16

    For consuming multipart form data. use @consumes tag & provide "multipart/form-data" along with value parameter like

    @Consumes(value = "multipart/form-data")

    refer https://jnorthr.wordpress.com/2012/07/10/http-header-content-type-and-encodings/

    0 讨论(0)
  • 2021-01-05 05:22

    I faced similar issue sometime back.

    The following code did the trick for me

    @POST
    @Consumes("multipart/form-data")
    public void yourMethod(<params>) throws Exception {
    }
    

    In short, it is I think the @Consumes annotation you are missing.

    0 讨论(0)
  • 2021-01-05 05:35

    It seems we found the problem, and it was related to the format of the request. The correct format should have been:

    Content-type: multipart/form-data, boundary=AaB03x
    
    --AaB03x
    content-disposition: form-data; name="mode"
    
    T--AaB03x
    
    content-disposition: form-data; name="type"
    
    M--AaB03x
    
    content-disposition: form-data; name="path"
    
    c:/img/--AaB03x
    
    content-disposition: form-data; name="image"; filename="image.jpg"
    Content-Type: image/jpeg
    Content-Transfer-Encoding: binary
    
    imgdata--AaB03x--
    

    Changing to this format allowed me to consume the other parameters.

    0 讨论(0)
提交回复
热议问题