0

My API returns an Excel (xslx) File for a GET Request. If a "Accept" Header is present, the binary result gets encoded/corrupt. I can send the request using fiddler with the minimum Headers required and everything works just fine. If i add an Accept Header like a browser does:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

The result gets larger (8kb instead of 4kb) and seems to be encoded in some way. Fiddler detects this encoding and asks to decode it. After decoding so, the result is valid again. When i use chrome browser instead, it downloads the larger (8kb) file, not decoded and therefor corrupt.

@GET
@Path("/export-report")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
//@Produces({ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" })
public Response exportReport() throws IOException {
    byte[] fileBytes = getFileBytes();
    String filename = "report.xslx";
    String mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    return Response.ok()
            .header("Content-Disposition", "attachment; filename=\"" + filename + "\"")
            .header("Content-Length", fileBytes.length)
            .entity(fileBytes)
            .header("Content-Type", mimeType)
            .build();
}

I tried returning a File, a InputStream and a byte Array, it didn't change a thing.

I also had a look at Input and Output binary streams using JERSEY?

I have no soltuion, any idea?

Community
  • 1
  • 1
kjartan
  • 19
  • 2
  • Can you paste a small portion of the "encoded" output? It sounds like the file could be base64 encoded but I'm not sure if I understand why that would happen. – stdunbar Jan 21 '17 at 18:37
  • Faced some issue like this with browser related to another service . Seems thee issue was due to Accept have extra details like */*;q=0.8 at the end , can u check if it helps by removing this part – gladiator Jan 24 '17 at 10:41

0 Answers0