2015-12-02 68 views
0

我只是從附近的StackOverflow上的社區中尋求幫助,使用Java中的REST API上傳XML或CSV文件。使用Java中的Rest Api上傳XML/CSV文件

網址:

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

請求Playload:

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

回答

0
  1. 名稱(name="aaaa.xml")需要與@FormDataParam中的值相同。這就是爲什麼它是空的,因爲它是錯誤的名稱。有沒有名字的任何一部分file

  2. 我沒有看到任何資料。數據應顯示在這些行之間。

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

    這也是你需要弄清楚的。

+0

感謝你的回答我昨天瞭解,從形式的name屬性來的問題。 這裏是在頂部使用的形式 – yougho

0

這裏的形式使用:

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