簡體   English   中英

在Java中使用Rest Api上傳XML / CSV文件

[英]Upload XML/CSV File using Rest Api in java

我只是從附近的社區尋求幫助,使用Java的REST API在StackOverflow上載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的值相同。 這就是為什么它為空的原因,因為它是錯誤的名稱。 沒有該名稱的部分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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM