I am having problems with repeated and multipolar forms, and I was hoping that someone might have the same problem or if I could, I could help me.
My goal is to download the file and some parameters at the same time. I tried this using @MultipartForm annotated to a POJO form:
@PUT @Path("/userdebug1/{userId}") @Consumes("multipart/form-data") @Produces("application/json;charset=UTF-8") public String updateUserDebug1( @MultipartForm UserRequestForm request ) { return request.getName(); }
With the form UserRequestForm is
public class UserRequestForm { @FormParam("name") String name; @FormParam("blob") @PartType("application/octet-stream") byte[] image; public String getName() { return name; } public void setName(String n) { this.name =n; } public byte[] getImage() { return image; } public void setImage(byte[] image) { this.image = image; } }
All this works well, except for the fact that the character encoding is broken . If I use the umlaut, it does not return properly. If I use the following method:
@PUT @Path("/userdebug2/{userId}") @Consumes("multipart/form-data") @Produces("application/json;charset=UTF-8") public String updateUserDebug2(MultipartFormDataInput form) { try { return form.getFormDataMap().get("name").get(0).getBodyAsString(); } catch (IOException e) { e.printStackTrace(); } return "error"; }
I used charlesproxy to send the same request to two of both urls. Here is one of them. The other differs only in the URL.
PUT /api/v1/userdebug1/A4BE364C-15F8-59B0-87C3-DCA0A123644A HTTP/1.1 Host: localhost:8081 Content-Type: multipart/form-data; charset=utf-8; boundary=0xKhTmLbOuNdArY-5C999EAA-3828-4919-98B7-19D4FD738814 Accept-Encoding: gzip Connection: close Content-Length: 205 --0xKhTmLbOuNdArY-5C999EAA-3828-4919-98B7-19D4FD738814 Content-Disposition: form-data; name="name" Content-Type: text/plain;charset=utf-8 ü --0xKhTmLbOuNdArY-5C999EAA-3828-4919-98B7-19D4FD738814--
Answer 1 (using the pojo form):
Answer 2 (using MultipartFormDataInput):
ü
Any ideas? Am I doing something wrong or is this a mistake?
Thank you for the amazing stackoverflow community. You have already helped a lot. Even if this is the first time I asked a question.