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 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.
This is the Request format:
Content-type: multipart/form-data
"Description": text/plain
"Path": text/plain
"Image": image/jpeg
How to correctly consume this kind of request and save the image server-side?
[EDIT]
I managed to consume multipart/form-data by using this:
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
)
{
However, when trying to consume the following POST request:
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--
I'm getting the following error:
javax.ws.rs.BadRequestException: org.apache.cxf.jaxrs.utils.multipart.MultipartReadException: No multipart with content id type found, request content type : multipart/form-data;boundary=AaB03x
When I consume only mode, for instance, it works fine. It only breaks for 2 or more parameters. Any idea for why is that wrong?