| GOLF(2gg) | Development | GOLF(2gg) |
NAME¶
send-file - (web)
PURPOSE¶
Send file to client.
SYNTAX¶
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> [ , ... ] ]
]
DESCRIPTION¶
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 directories). 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.
HEADERS
The following are subclauses that allow setting any custom header:
send-file "somepic.jpg" headers cache-control "max-age: 3600"
out-header use custom "CustomOption3"="CustomValue3", "Status"="418 I'm a teapot"
"custom" subclause lets you use any custom headers that exist today or may be added in the future, as well as any headers of your own design.
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 (i.e. display):
send-file "/home/golf/files/myfile.jpg" headers content-type "image/jpg"
An example to display a PDF document:
set-string pdf_doc="/home/mydir/myfile.pdf" send-file pdf_doc headers content-type "application/pdf"
If you want to send a file 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
| $VERSION | $DATE |