John,

Also, if you want to avoid an extra temp file/s on disk avoid
ns_getform and just use [ns_conn files] directly with [fcopy]. The
example in ns_getform is one way to do it by hand. Here is my updated
slightly safer ns_getform:

## ns_getform made saf(er)
# An improved version would return the open fp instead of the tmpfile,
# or better use a system call which returns an fp

rename ns_getform ns_getform_unsafe

#
# ns_getform --
#
#       Return the connection form, copying multipart form data
#       into temp files if necessary.
#

proc ns_getform {{charset ""}}  {

    global _ns_form _ns_formfiles

    #
    # If a charset has been specified, use ns_urlcharset to
    # alter the current conn's urlcharset.
    # This can cause cached formsets to get flushed.
    if {$charset != ""} {
        ns_urlcharset $charset
    }

    if {![info exists _ns_form]} {
        set _ns_form [ns_conn form]
        foreach {file} [ns_conn files] {
                set off [ns_conn fileoffset $file]
                set len [ns_conn filelength $file]
                set hdr [ns_conn fileheaders $file]
                set type [ns_set get $hdr content-type]
                set fp ""
                while {$fp == ""} {
                        set tmpfile [ns_tmpnam]
                        set fp [ns_openexcl $tmpfile]
                }
                fconfigure $fp -translation binary
                ns_conn copy $off $len $fp
                close $fp
                ns_atclose "ns_unlink -nocomplain $tmpfile"
                set _ns_formfiles($file) $tmpfile
                #ns_set put $_ns_form $file.content-type $type
                # NB: Insecure, access via ns_getformfile.
                #ns_set put $_ns_form $file.tmpfile $tmpfile
        }
    }
    return $_ns_form
}

tom jackson


On Fri, Nov 20, 2009 at 12:21 PM, John Buckman <[email protected]> wrote:
> On Nov 19, 2009, at 8:56 AM, Tom Jackson wrote:
>
>> There is a configuration setting which saves posted files to disk.
>> You need the ns_limits maxupload to be large enough, then maxinput
>> (not sure which config section) sets an upper limit for in memory
>> data.
>
> Yes, the naviserver people talked about that, but the problem is that then 
> you get the raw data, that you need to do something with, rather than 
> temporary files.
>
> I'm currently trying out naviserver, as they do seem to have solved the 
> large-file-upload problem that aolserver has.  It's working for me, and nsd 
> process size is staying at 50mb even with multiple gig file uploads being 
> handled.
>
> The main thing that naviserver has, that would probably work simply on 
> aolserver, is a ns_parseformfile function, which parses the raw upload data 
> in a memory efficient way. Here is what the code looks like:
>
> set tmpfile [ns_conn contentfile]
> ns_parseformfile $tmpfile $form [ns_set iget [ns_conn headers] content-type]
> array set formdata [ns_set array $form]
>
> It might straightforward to copy the "ns_conn contentfile" and 
> "ns_parseformfile" functions to aolserver to solve this problem.


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to 
<[email protected]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to