使用 angularjs 上传文件和文本字段后将数据​​保存为 java 对象

Saving data as java object after uploading file and text fields using angularjs

我正在使用 ng-fileupload 并尝试捕获两个自定义文本字段。我的 ui 代码类似于 http://jsfiddle.net/danialfarid/maqbzv15/1118/

使用fiddle发送的请求如下:

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--

我想捕获 java 对象中的字段和文件。我正在尝试使用类似这样的东西

    @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");

}

但是,我无法弄清楚如何获取字段的文本值,即 userName=hello,xmlFileName=abc.xml。

试试这个对类似问题的回答 http://howtodoinjava.com/resteasy/jax-rs-resteasy-file-upload-html-form-example/