I am writing little web app uploading the file to a web server. I got everything working, but I became puzzled by the fact that almost all parameters send from the client (browser) must be on the server side injected with the word @FormDataParam
except FormDataMultiPart
type parameter.
Can somebody explain that to me, please?
Regards,
Janusz
Generally, all entity body parameters are the parameter without any annotation. Such as with JSON or XML, you would see
@POST
@Consumes({"application/json", "application/xml"})
public Response post(RequestEntity entity) {
}
Here, the MessageBodyReader
that handles JSON or XML would be used to handle deserializing the entity stream into the ResponseEntity
.
This is the same with FormDataMultiPart
. There is a MessageBodyReader
to handle deserializing the entire multipart stream and creating the FormDataBodyPart
for the JAX-RS runtime to pass to the resource method when it is called.
@FormDataParam
is treated more like @FormParam
, @PathParam
, @QueryParam
, etc. We can have multiple parameters. Each parameter for this annotation represent a single part of the multipart request.
So we have the option to either get the entire request into a single entity with FormDataMultiPart
or we can get them pre-separated into individual parts. If we used FormDataMultiPart
, we would have to extract all the parts manually from it. We would use this in such a case where the name of each part is not known. Or there are many parts, where declaring each one is not pleasing to the coder.