使用java中的Rest-Api上传XML/CSV文件



我只是向附近的社区寻求帮助,帮助StackOverflow使用Java中的REST API上传XML或CSV文件。

网址:

Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/HSMV5/api/import
Request Method:POST

请求播放负载:

------WebKitFormBoundaryTnLhEykB6lreFMtz
Content-Disposition: form-data; name="aaaa.xml"; filename="aaaa.xml"
Content-Type: text/xml

------WebKitFormBoundaryTnLhEykB6lreFMtz--

这是我的源代码:

@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.MULTIPART_FORM_DATA })
public class Dispatcher {
    @POST
    @Path("/import")
    public Response importpostFile(
            @FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail)
            throws HsmRestServiceException {
        System.out.println(fileDetail.getFileName());
        return importFile.doPost(null);
    }
}

编译时变量返回null:

uploadedInputStream : null
fileDetail : null
  1. 名称(name="aaaa.xml")需要与@FormDataParam中的值相同。这就是它为null的原因,因为它是错误的名称。没有名称为file 的部件

  2. 我没有看到任何数据。数据应显示在这些行之间。

    Content-Type: text/xml
    
    ------WebKitFormBoundaryTnLhEykB6lreFMtz-- 
    

    这也是你需要弄清楚的。

这里是要使用的表单:

     <tr class="pairRowTab">
            <td>
                <bean:message key="table.dateFormat"/>
            </td>
            <td>
                <html:file property="dateFormatFile" size="70"/>
            </td>
        </tr>
        <tr class="impairRowTab">
            <td>
                <bean:message key="table.separateur"/>
            </td>
            <td>
                <html:file property="separateurFile" size="70"/> 
            </td>
        </tr>

最新更新