KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to allow file downloads from 4D Web Server
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: October 13, 2000

Lets say, for example, you are generating some data internally in 4D in the form of tab-delimited text or perhaps XLS format, and want to be able to send that to a web browser and initiate a file download.

There are two basic options for sending files to a browser, and two slightly more complex options (not to mention various combinations of the following techniques):

1. Simply save the file to the 4D Server's hard drive and provide an HREF link to it that the user can click. What happens when the user clicks the link depends on the file's extension and how it is mapped to a MIME type inside the user's web browsing software. For example, most web browsers will automatically display the contents of a .TXT or .HTM file directly inside the window (the user could still use File->Save As... to create a disk file from the window contents). However, a .XLS file cannot be properly displayed by a browser and would normally cause the user to be prompted about what to do with it - allowing them to save it to their disk.
2. Use the command SEND HTML BLOB and provide an explicit MIME type along with the file name. The same comments about the web browser MIME mapping preferences apply as explained above. Note that a ZIP or other compressed archive file format might also be a good choice since universally browsers know that such files need to be saved to disk. However, there is no built-in way in 4D to create such a file without using an external utility program or perhaps a 3rd party Plug-in.
3. Use custom JavaScript embedded inside and HTML page to initiate the file transfer (using one of the techniques described above to enable the transmission from inside of 4D). This way the user doesn't have to lift a finger for the transfer to begin. For a nice example of this, try downloading a file from Shareware.com
4. Utilize an external FTP Server (either on the same machine or remotely) to store the file from 4D using either the local hard drive, file sharing or the Internet Commands Plug-in. Then provide a link as in (1) above to allow the user to initiate file transfer. Note that 4D does NOT include an FTP server, the IC Plug-in simply allows FTP client functions to be employed. The advantage of using FTP is offloading processing of the task from the web server, and that FTP is more robust for large files than HTTP.