2014-10-18 2 views
1

아래의 예제를 사용하여 테스트했습니다. REST API는 작동하지만 스트림 형식의 결과를 제공합니다. 그러나 파일 옵션을 사용하면 결과가 예상됩니다. 이 예제를 사용하여 Angular JS 프레임 워크를 구현했습니다.REST 서비스에서 엑셀 파일을 응답으로 설정하십시오.

@GET 
    @Path("/get") 
    @Produces("application/vnd.ms-excel") 
    public Response getFile() { 
    LOG.info("get - Function begins from here"); 

    File file = new File("/home/test/file.xls"); 

    ResponseBuilder response = Response.ok((Object) file); 
    response.header("Content-Disposition", 
     "attachment; filename=new-excel-file.xls"); 
    response.header("Content-Type","application/octet-stream"); 
    return response.build(); 

    } 
+0

** 내 질문에 여기 해결책을 발견 http://stackoverflow.com/questions/22447952/angularjs-http-post-convert-binary-to-excel-file-and-download** – Srini

답변

1

응용 프로그램/octet-stream을가 RFC 2046에서 "임의의 이진 데이터"로 정의되어 있으므로 파일이

가 옥텟 스트림 마임에 대해 this answer에서 살펴 response.header("Content-Type","application/vnd.ms-excel");위한 엑셀 하나의 변화 response.header("Content-Type","application/octet-stream"); 것을 제공 유용 할 수 있으며, excel MIME 형식에 대해서는 this one입니다.

+0

예 , 빠른 답변 주셔서 감사합니다. ** response.header ("Content-Type", "application/octet-stream"); ​​**을 제거하고 시도했지만 여전히 파일 저장 대화 상자를 표시하지 않습니다. – Srini

+0

@ user1702169 파일 처리 방법에 대한 동작은 브라우저가 아니라 API의 서버 쪽에서 설정할 수있는 것으로 생각합니다. – th3morg

+0

@ th3morg이 답변이 링크 된 첫 번째 답변과 마찬가지로'Content-Disposition' 헤더 만 설정할 수 있습니다. –

관련 문제