I'm trying to use DownloadLink with a static Excel file in my resources directory and everything appears to be working just fine except that the file doesn't open in Excel (Excel complains that it is corrupt).
Everything works fine if I download a .txt or .jpg file, but not with .xlsx, .xls, or .zip files. This tells me that some binary files do in fact work, but not Excel or Zip files.
Do I need to set the response headers specific for Excel?
Here's my code:
String templatePath = MyPage.class.getResource("").getPath() + "template.xlsx";
File templateFile = new File(templatePath);
form.add(new DownloadLink("templateLink", templateFile));
I have added a content type specific to xlsx files, and the file is still being corrupted. The download dialog window in the browser (FF4) now recognizes that it's an Excel Workbook (as opposed to a binary file as it was doing before), but the file is still being corrupted somewhere along the line. One other odd thing is that the file size of the downloaded file is different than the original file in the resources folder.
The error was actually caused by Maven during the copy resources execution phase. We have filtering turned on for the resources directory and it was clobbering the excel files. I added a rule for xlsx files to not be filtered and all is well now.