18.4.0 released Sep 25, 2023
Send file

Purpose: Send file to client.

send-file <file> [ headers \
    [ content-type <content type> ] \
    [ download [ <download> ] ] \
    [ etag [ <etag> ] ] \
    [ file-name <file name> ] \
    [ ( cache-control <cache control> ) | no-cache ] \
    [ status-id <status id> ] \
    [ status-text <status text> ] \
    [ custom <header name>=<header value> [ , ... ] ]
    ]

When a client requests download of a file, you can use send-file to provide <file>, which is its location on the server, and is either a full path or relative to the application home directory (see vv). Note however that you can never use dot-dot (i.e. "..") in <file> - this is a security measure to avoid path-traversal attacks. Thus the file name should never have ".." in it, and if it does, the program will error out and stop.
Headers
The following are subclauses that allow setting any custom header:
Cookies
Any cookies set prior to send-file (see set-cookie and delete-cookie) will be sent along with the file to the web client.
Examples
To send a document back to the browser and show it, use send-file with the "show" clause:
send-file "/home/vely/files/myfile.jpg" headers content-type "image/jpg"

An example to display a PDF document:
char *pdf_doc="/home/mydir/myfile.pdf";
send-file pdf_doc headers content-type "application/pdf"

If you want to send a file to the client for download (with the dialog), use "download" clause. This way the document is not displayed but the "Save As" (or similar) window shows up, for example to download a "PDF" document:
send-file "/home/user/file.pdf" headers download content-type "application/pdf"

See also
Web
call-web  
out-header  
send-file  
silent-header    
See all
documentation


You are free to copy, redistribute and adapt this web page (even commercially), as long as you give credit and provide a link back to this page (dofollow) - see full license at CC-BY-4.0. Copyright (c) 2019-2023 Dasoftver LLC. Vely and elephant logo are trademarks of Dasoftver LLC. The software and information on this web site are provided "AS IS" and without any warranties or guarantees of any kind.