0

I'm generating a csv/xls file but when I use the postman to test the rest controller, I'm getting a lot of special chars but the file itself is being generated properly. image with spec chars

so, the file generated has literally 3 lines and 2 rows.
these are my HttpHeaders:
-headers.set(HttpHeaders.CONTENT_TYPE, "text/csv;charset=ISO-8859-1");
-headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);

dcm50
  • 103
  • 3
  • 13
  • 2
    Looks like binary data shown as text. Does not make much sense to me. – Seelenvirtuose Jul 19 '22 at 14:50
  • Is this the output from the top? Or is it perhaps beginning with the letters PK? – Sam Jul 19 '22 at 14:51
  • 1
    What encoding is the controller using? You have a header specifying Latin1. Is that a request header or a response header? I'm guessing the latter, but I don't think your controller is really returning Latin1. – David Conrad Jul 19 '22 at 14:57
  • 4
    Hidden within the first line appear the letters "Root entry". This seems to be a binary .xls file (Excel versions before 2007) – Thomas Kläger Jul 19 '22 at 14:57
  • 1
    Does this answer your question? [What is correct content-type for excel files?](https://stackoverflow.com/questions/2937465/what-is-correct-content-type-for-excel-files) – Valerij Dobler Jul 19 '22 at 15:20
  • @DavidConrad Is a response header. How do I change the specifitacion of the header? – dcm50 Jul 19 '22 at 15:30
  • Change it to the content-type matching your actual content: [Excel content types](https://stackoverflow.com/a/2938188/636009) – David Conrad Jul 19 '22 at 15:44
  • Still not working even changing to -> headers.set(HttpHeaders.CONTENT_TYPE, "application/vnd.ms-excel"); – dcm50 Jul 19 '22 at 15:59
  • What do you mean by "not working"? That Postman decode the binary? It will not, no matter the encoding. – Valerij Dobler Jul 19 '22 at 19:21
  • Instead of sending the request, you click on the down-chevron to the right of the send button and save the response and open it in excel. – Valerij Dobler Jul 19 '22 at 19:22
  • ok, I did that and there's a way to put the extension when I going to save the file? https://imgur.com/1VU72Sm When I debbug the code, I can see that the String with the file name is being saved wiht the properly extension (csv or xls) – dcm50 Jul 19 '22 at 20:03

0 Answers0