Note that there are some explanatory texts on larger screens.

plurals
  1. POConsuming a multipart/form-data via RESTful CXF
    primarykey
    data
    text
    <p>I've been working in a webservice that consumes and produces JSON files using Apache CXF in conjuction with Jackson. <br/> However, one of the service's methods should be able to save an uploaded image from a mobile application that makes a multipart/form-data POST request to my webservice, and I don't know how to treat this kind of content-type within my context. We usually create "Request" and "Response" objects to consume and produce the JSON, however, I'm afraid this would not work for this case.</p> <p>This is the Request format:</p> <pre><code>Content-type: multipart/form-data "Description": text/plain "Path": text/plain "Image": image/jpeg </code></pre> <p>How to correctly consume this kind of request and save the image server-side?</p> <hr> <p><strong>[EDIT]</strong></p> <p>I managed to consume multipart/form-data by using this:</p> <pre><code>public returnType savePicture( @Multipart(value = "mode", type = "text/plain") String mode, @Multipart(value = "type", type = "text/plain") String type, @Multipart(value = "path", type = "text/plain") String path @Multipart(value = "image", type = "image/jpeg") Attachment image ) { </code></pre> <p>However, when trying to consume the following POST request:</p> <pre><code>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-- </code></pre> <p>I'm getting the following error: </p> <blockquote> <p>javax.ws.rs.BadRequestException: org.apache.cxf.jaxrs.utils.multipart.MultipartReadException: No multipart with content id <strong>type</strong> found, request content type : multipart/form-data;boundary=AaB03x</p> </blockquote> <p>When I consume only <strong>mode</strong>, for instance, it works fine. It only breaks for 2 or more parameters. Any idea for why is that wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload