2014-09-16 4 views
0

xls을 업로드하려고합니다. 나는 나머지 웹 서비스 아래에 쓴 나는 또한 스프링 애플리케이션 컨텍스트 설정에 아래에 추가 한MultipartFile이 spring3으로 널로 설정되고 나머지가 cxf가됩니다

@POST 
@Path("/ui/uploadDocument") 
@Consumes("multipart/form-data") 
public void uploadDocument(@RequestParam("file") MultipartFile file) 

:

<bean id="multipartResolver" 
     class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
    <property name="maxUploadSize" value="99999"/> 
    <property name="maxInMemorySize" value="99999"/> 
</bean> 

가 지금은 크롬 나머지 클라이언트와 간단한 html 코드를 사용하여 위의를 실행하려고 아래처럼 :

<form method="POST" action="http://localhost/my-core/eCom/v1/catalogue/ui/uploadDocument" enctype="multipart/form-data"> 
    File to upload: <input type="file" name="file" id="file"><br /> 
    Name: <input type="text" name="name"><br /> <br /> 
    <input type="submit" value="Upload"> Press here to upload the file! 
</form> 

나머지 클라이언트 또는 HTML 코드를 통해 호출하는 문제는 나머지 호출이 성공적이지만 호출되었지만 파일 (MultipartFile)이 null로 설정되었습니다. 위의 설정을 놓친 적이 있습니까? 우리는 스프링 3.0을 사용하고 나머지 지원을 위해 우리가 아파치 jaxrs를 사용하는

은 ... anyones에 도움이

답변

0

는 드디어 JAX R과 방법을 수행하여 문제를 해결 ... 감사합니다. 다음은

코드입니다 : 호출하는 데 사용

@POST 
@Path("/ui/uploadDocument") 
@Consumes("multipart/form-data") 
public Response uploadDocument(List<Attachment> attachments, @Context HttpServletRequest request) { 
    for (Attachment attachment : attachments) { 
     DataHandler handler = attachment.getDataHandler(); 
     try { 
    //   Creates a workbook object from the uploaded excelfile 
      HSSFWorkbook workbook = new HSSFWorkbook(handler.getInputStream()); 
      HSSFSheet worksheet = workbook.getSheetAt(0); 
      int i = 1; 
      while (i <= worksheet.getLastRowNum()) { 
       HSSFRow row = worksheet.getRow(i++); 
       CatDefault catDefault = new CatDefault(); 
       catDefault.setCatId((long) row.getCell(0).getNumericCellValue()); 
      } 
     } 
    } 

HTML 코드를 다음과 같습니다 : CXF가 유용

<form action="http://localhost/cat-core/eCom/v1/catalogue/ui/uploadDocument" method="post" enctype="multipart/form-data"> 
    <p> 
     Select a file : <input type="file" name="uploadedFile" size="50" /> 
    </p> 
    <input type="submit" value="Upload It" /> 
</form> 

연결합니다.