I am using ng-fileupload and trying to capture two custom text fields. My ui code is similar to http://jsfiddle.net/danialfarid/maqbzv15/1118/
The request send using fiddle is as follows:
POST http://localhost:8081/test-ui/api/uploadXml HTTP/1.1
Host: localhost:8081
Connection: keep-alive
Content-Length: 547
Accept: application/json, text/plain, */*
Origin: http://localhost:8081
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryziDfCPZA550MEOaA
Referer: http://localhost:8081/ec-ui/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
------WebKitFormBoundaryziDfCPZA550MEOaA
Content-Disposition: form-data; name="userName"
hello
------WebKitFormBoundaryziDfCPZA550MEOaA
Content-Disposition: form-data; name="xmlFileName"
abc.xml
------WebKitFormBoundaryziDfCPZA550MEOaA
Content-Disposition: form-data; name="file"; filename="note.xml"
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
------WebKitFormBoundaryziDfCPZA550MEOaA--
I want to capture the fields and file in a java object. I was trying to use something like this
@Path("/uploadXML")
@POST
@Consumes("multipart/form-data")
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public FileUploadResponse handleFileUpload(MultipartFormDataInput input) throws Exception {
Map<String, List<InputPart>> formParts = input.getFormDataMap();
List<InputPart> inFileNames = formParts.get("xmlFileName");
List<InputPart> inUserNames = formParts.get("userName");
List<InputPart> inFiles = formParts.get("file");
}
however, i am not being able to figure out how to get the text values of fields i.e userName=hello, xmlFileName=abc.xml.
try this answer to similar problem http://howtodoinjava.com/resteasy/jax-rs-resteasy-file-upload-html-form-example/