2

I used the below example to test. REST Api works, but it gives result in stream format. But,I expect result with file option. I used this example to ingrate with Angular JS framework.

@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();

  }
Srini
  • 823
  • 5
  • 10
  • 29
  • **I have found solution here to my question http://stackoverflow.com/questions/22447952/angularjs-http-post-convert-binary-to-excel-file-and-download** – Srini Nov 11 '14 at 12:16

1 Answers1

2

application/octet-stream is defined as "arbitrary binary data" in RFC 2046, so given that the file is an excel one change response.header("Content-Type","application/octet-stream"); for response.header("Content-Type","application/vnd.ms-excel");

take a look at this answer about octet stream mime type, might be useful, and this one about excel mime type.

Community
  • 1
  • 1
thebigwhoop
  • 56
  • 1
  • 3
  • Yes, thanks for quick answer. I have removed **response.header("Content-Type","application/octet-stream");** and tried,but still it does not give file save dialog box. – Srini Oct 20 '14 at 09:35
  • @user1702169 I believe the behavior of how the file is handled is by browser, not by something you can set on the server side of an API. – th3morg Oct 20 '14 at 17:58
  • @th3morg sure you can, just set the `Content-Disposition` header, as in the first answer this answer links to. – Jon Hanna Dec 12 '14 at 19:54