I'm facing a problem to make a angular crud with jax-rs on backend. The crud is very simple, some text fields and a image field.
I have the code working to upload a image:
@POST
@Consumes("multipart/form-data")
public Response uploadFile(MultipartFormDataInput input) {
...
}
And in the html layer:
<form action="http://localhost:8080/app/api/user" method="post" enctype="multipart/form-data">
<p>
Choose a file : <input type="file" name="file" />
</p>
<input type="submit" value="Upload" />
</form>
So, my question is how can I do this in one step like this:
@POST
@Consumes("multipart/form-data")
public Response save(MultipartFormDataInput input, MyEntity entity) {
...
}
If I try to call the code above from view layer, the wildfly give a error that doesn't found data to bind with MyEntity parameter.
[org.jboss.resteasy.core.ExceptionHandler] (default task-3) failed to execute: javax.ws.rs.NotSupportedException:
Could not find message body reader for type: class mypackage.MyEntity of content type: multipart/form-data;boundary=----WebKitFormBoundaryRXVvqLpZACPylNgS
Does anyone knows how can I do that? Or shoud I do it in two steps?
Technically, you can just get both pieces of data from the
MultipartFormDataInput
. For exampleIf you want to put everything into a POJO, you can do something like this
Then in your resource method
See more: