gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:46:54 25 4
gpt4 key购买 nike

我正在使用 ng-fileupload 并 try catch 两个自定义文本字段。我的 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。

最佳答案

关于java - 使用angularjs上传文件和文本字段后将数据​​保存为java对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36329801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com