2016-01-27 85 views
3

讀取上傳文件的詳細信息我已經實現上傳多個文件REST服務爲server.But的問題是,如果我使用FormDataMultiPart在REST service.I可以得到文件內容我不能得到文件的詳細信息。像明智的,我試圖得到類似下面的文件細節,它給了我一個錯誤說,不支持。如何在澤西

@POST 
    @Consumes(MediaType.MULTIPART_FORM_DATA) 
    public void upload(FormDataMultiPart formParams) 
    { 
     Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields(); 

     //Assume i am sending only files with the request 

     for (List<FormDataBodyPart> fields : fieldsByName.values()) 
     { 
      for (FormDataBodyPart field : fields) 
      { 

       InputStream is = field.getEntityAs(InputStream.class); 
       String fileName = field.getName(); 
       field.getMediaType(); 
       //Those work perfectly 

    //This gave me an error 
    FormDataContentDisposition f=field.getEntityAs(FormDataContentDisposition .class); 
    System.out.println(f.getFileName()); 

      } 
     } 
    } 

請讓我知道我能得到這樣的type,name,size文件的詳細信息爲每個上傳的文件,如果使用FormDataMultiPart

回答

5

我能夠最終在這裏訪問文件的細節是代碼片段。

@POST 
    @Consumes(MediaType.MULTIPART_FORM_DATA) 
    public void upload(FormDataMultiPart formParams) 
    { 
     Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields(); 

     //Assume i am sending only files with the request 

     for (List<FormDataBodyPart> fields : fieldsByName.values()) 
     { 
      for (FormDataBodyPart field : fields) 
      { 

       InputStream is = field.getEntityAs(InputStream.class); 
       String fileName = field.getName(); 
       field.getMediaType(); 


    //This working fine 
    FormDataContentDisposition f=field.getFormDataContentDisposition(); 
    System.out.println(f.getFileName()); 

      } 
     } 
    } 
+1

更多信息http://stackoverflow.com/questions/35012784/how-to-send-selected-file-list-when-submit-button-click-in-angularjs/35059871#35059871 – gihan