xowiki::File instproc www-download (public)
<instance of xowiki::File> www-download
Defined in /var/www/openacs.org/packages/xowiki/tcl/xowiki-www-procs.tcl
This web-callable method downloads the file content of the current File object. The following query parameter can be used to influence the behavior
- Testcases:
- xowiki_test_cases
Source code: # # The package where the object is coming from might be different # from the package on which it is delivered. Use the latter one # with the proper delivery information. # set package_id [::xo::cc package_id] # # Use always ad_returnfile_background, it is clever enough to use # the right delivery mode in case of doubt. # if {[:exists_query_parameter filename]} { set fn [::xo::backslash_escape \" [:query_parameter filename]] ns_set put [ns_conn outputheaders] Content-Disposition "attachment;filename=\"$fn\"" } set full_file_name [:full_file_name] if {![ad_file exists $full_file_name]} { # # This should not happen on a production system. In certain # testing setups, a system admin might not have provided the # full content repository. We fail more gracefully in this # case. # ad_log error "The file '$full_file_name' does not exist." "Maybe the content repository is (partially) missing?" return [::${:package_id} error_msg -status_code 500 [subst { No file for link <b>'[ns_quotehtml [ns_conn url]]'</b> available.<br> Please report this to the web master of this site. }]] } ::$package_id set mime_type ${:mime_type} ::$package_id set delivery ad_returnfile_background #:log "--F FILE=$full_file_name // ${:mime_type}" set geometry [::xo::cc query_parameter geometry ""] if {[string match "image/*" ${:mime_type}] && $geometry ne "" } { if {![regexp {^\d*x?\d*$} $geometry]} { error "invalid geometry $geometry" } set tmpdir [ad_tmpdir] if {![ad_file isdirectory $tmpdir/$geometry]} { file mkdir $tmpdir/$geometry } set scaled_image $tmpdir/$geometry/${:revision_id} if {![ad_file readable $scaled_image]} { set cmd [::util::which convert] if {$cmd ne ""} { if {![catch {exec $cmd -geometry $geometry -interlace None -sharpen 1x2 $full_file_name $scaled_image}]} { return $scaled_image } } } else { return $scaled_image } } set modtime [ad_file mtime $full_file_name] set cmptime [ns_set iget [ns_conn headers] If-Modified-Since] if {$cmptime ne ""} { if {[clock scan $cmptime] >= $modtime} { # # TODO: we should set the status_code and delivery the same # way, ... but keep things compatible for now. # ::xo::cc set status_code 304 ::$package_id set delivery ns_return return "" } } ns_set put [ns_conn outputheaders] Last-Modified [ns_httptime $modtime] return $full_file_nameXQL Not present: Generic, PostgreSQL, Oracle