Downloading uploaded docx or xlsx files in Mendix

3
Hi Everybody, I have a datagrid in which I want to display a link to an uploaded file, which results in a download when you click on it. With this link this works nice for pdf documents, for doc documents for txt documents..... but.... It does not work as expected with docx or xlsx documents (the Office 2007 / 2010 file formats). Is this a Mendix thing? Or is this a browser thing? Anyway: Question 1: How can I make it in a way that the system will recognize it als (respectively) Word and Excelfiles, and open it in the browser in the associated program? Question 2 How can I arrange that the "original filename" will be proposed by the browser when you choose "save as" after clicking the link? Thanks in forward for the answer! Roberto --> edit: the current behavior, when clicking on a download link of the docx or xlsx file is that the browser tries to download a file, named file (no extension). Chrome and Firefox don't recognize it at all, Internet Explorer thinks it is a compressed file/zip-file, but no association to word/excel
asked
3 answers
1

This is not a mendix thing I think. The only thing that could make a difference is the option "show file in browser". Try to change this setting. We have this option set to false in different forms we're we can upload and download files. alt text

When I try to download a docx file, my browser offers me two options. Open the file and save the file. When I open the file, Microsoft Word opens my file correctly. So after handling the file in your browser, your computer should take the lead to open it. You meantioned that the file you want to open has no extension. I thinks that's your problem. Because it has no extension, your computer doesn't know that it's a word or excel file.

Edit after comment: Maybe you could associate a filedocument to your object and then retrieve the guid of the file and set this a link in a virtual attribute. Or maybe using deeplinks. These are things you can't do simply by adding those files in your datagrid. See this explanation

answered
1

Ok, I will test things with deeplinks and the suggestion of Michel for my datagrid. But can I expect that this makes the browser recognize this as a Word/Excel document? (If so, then the writing below is unnecessary.)

I tested 2 things to know more of downloading docx/xlsx files in browsers:
- just a simple link <a href="test.docx">test</a> in a separate html file works for (my) browsers: the download is recognized as Word-doc.
- I think the "simple link example" cannot be compared to the Mendix-situation (because of the explanation-link from Samet Kaya, so I created a download-script in PHP like this

<?php
$dir      = ""; //zelfde map
$file = 'Test.docx';
if ((isset($file))&&(file_exists($dir.$file))) { 
   header("Content-type: application/force-download"); 
   header('Content-Disposition: inline; filename="' . $dir.$file . '"'); 
   header("Content-Transfer-Encoding: Binary"); 
   header("Content-length: ".filesize($dir.$file)); 
   header('Content-Type: application/octet-stream'); 
   /*Note that if I comment out the line below, the behaviour is like mendix: the download is not recognized as a Worddoc but as a zip-file or unknown extension*/
   header('Content-Disposition: attachment; filename="' . $file . '"'); 
   readfile("$dir$file"); 
}
?>

When I execute this script, I also get a file-download where the name is Test.docx is the filename and it is recognized as a Worddoc

Question: Is the Mendix-file-download so different that I cannot get this behaviour in mendix-apps? Or can I configure my webserver in a way that it still is recognized (I read something of missing MIME-types)?

answered
0

In answer to Michel's comment (compare headers) I below post the part that (I think) is relevant:

Headers of the Mendix-download
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Server: Jetty(7.0.1.v20091125)

Headers of the php-script HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Wed, 23 Feb 2011 09:55:12 GMT
X-Powered-By: ASP.NET, PHP/5.3.4
Connection: close
Content-Type: application/octet-stream
Content-Disposition: inline; filename="Test.docx"
Content-Transfer-Encoding: Binary
Content-Length: 9969

I think the line marked in bold is important. Can this header be added (without needing a new version of the Mendix-Modeler)?

answered