0

In edge, I am accessing a JSP page that returns me a file. It works perfectly in chrome but in Edge and Internet explorer I am getting the mime type appended to the filename.

This is the response header:

enter image description here

Edge asked me to save the file and the filename is

persistenceIDs.xlsx.vnd.openxmlformats-officedocument.spreadsheetml.sheet

Any ideas?

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
Gaetan56
  • 519
  • 2
  • 6
  • 17
  • Do you want to prevent its happening, or are you content just to deal with it if it does (for instance if you find more than 2 dots, take a substring from 0 to the position of the second dot)? – Jeremy Kahan Jul 17 '19 at 14:18
  • in Chrome, the file is downloaded as "persistenceIDs.xlsx" as it should be but not in Edge or IE. I'd like to understand why it's not using the filename specified in the header? – Gaetan56 Jul 17 '19 at 15:07
  • If you try to provide any sample code to produce the issue than we can try to make a test and try to find any possible solution for the issue. – Deepak-MSFT Jul 18 '19 at 02:13

1 Answers1

0

This seems to be an example of mime sniffing, which is odd given that you have nosniff in your header (but from what I am reading online, sometimes these browsers are stubborn). There is stuff out there about how to reset your browser or edit the registry, but I wrote a little function to manage the result instead. Str contains the filename, and the code changes it if needed, leaves it alone otherwise.

int second = -1;

 int first = str.indexOf(".");
   if (first>-1){
        second = str.indexOf(".", first + 1);
   }
   if (second>-1){
       str=str.substring(0, second);
   }

adapted from: Finding second occurrence

Jeremy Kahan
  • 3,796
  • 1
  • 10
  • 23