xowiki::File instproc www-download (public)

 <instance of xowiki::File[i]> www-download

Defined in 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

Partial Call Graph (max 5 caller/called nodes):
%3 test_xowiki_test_cases xowiki_test_cases (test xowiki) xowiki::File instproc www-download xowiki::File instproc www-download test_xowiki_test_cases->xowiki::File instproc www-download ad_file ad_file (public) xowiki::File instproc www-download->ad_file ad_log ad_log (public) xowiki::File instproc www-download->ad_log ad_tmpdir ad_tmpdir (public) xowiki::File instproc www-download->ad_tmpdir util::which util::which (public) xowiki::File instproc www-download->util::which xo::backslash_escape xo::backslash_escape xowiki::File instproc www-download->xo::backslash_escape

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_name
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: