#!/usr/bin/wapptclsh # # This script demonstrates a Wapp application that can accept a file # upload using # package require wapp proc common-header {} { wapp-trim {
Show the script that generates this page
} # Ordinary query parameters come through just like normal if {[wapp-param showenv 0]} { wapp-trim {%html([wapp-debug-env])} } # File upload query parameters come in three parts: The *.mimetype, # the *.filename, and the *.content. set mimetype [wapp-param file.mimetype {}] set filename [wapp-param file.filename {}] set content [wapp-param file.content {}] if {$filename!=""} { wapp-trim {
Filename: %html($filename)
MIME-Type: %html($mimetype)
}
if {[string match image/* $mimetype]} {
# If the mimetype is an image, display the image using an
# in-line mark. Note that the content-security-policy
# must be changed to allow "data:" for type img-src in order
# for this to work.
set b64 [binary encode base64 $content]
wapp-trim {
Content:
} } else { # Anything other than image, just show it as text. wapp-trim { Content:
} } } common-footer } proc wapp-page-self {} { wapp-cache-control max-age=3600 common-header set fd [open [wapp-param SCRIPT_FILENAME] rb] set script [read $fd] close $fd wapp-trim {%html($content)
%html($script)} common-footer } proc wapp-page-style.css {} { wapp-mimetype text/css wapp-cache-control max-age=3600 wapp-trim { pre { border: 1px solid black; padding: 1ex; } } } wapp-start $argv