Forum OpenACS Q&A: upload file problem

Collapse
Posted by James Thornton on
I am having trouble with uploading files (the form var for the uploaded file is upload_file):
Error: could not read "": no such file or directory
could not read "": no such file or directory
    while executing
"file size $tmp_filename"
    invoked from within
"if { ![info exists upload_file] || [empty_string_p $upload_file] } {
    append exception_text "<li>Please specify a file to
upload
"
    incr except..."
Here's the actual code snippet...
if { ![info exists upload_file] || [empty_string_p $upload_file] } {
    append exception_text "<li>Please specify a file to
upload
"
    incr exception_count
} else {
    # this stuff only makes sense to do if we know the file exists
    # ns_queryget:
    #   http://www.aolserver.com/docs/tcldev/tapi-c98.htm#191488	
    set tmp_filename [ns_queryget upload_file.tmpfile]

    set file_extension [string tolower [file extension $upload_file]]

    # remove the first . from the file extension
    regsub "." $file_extension "" file_extension

    set guessed_file_type [ns_guesstype $upload_file]

    set n_bytes [file size $tmp_filename]
The ns_queryget doc says...
set x [ns_queryget name]
If "name" is a key in the query data, the variable x will be set to the value associated with the "name" key. If "name" is not a key in the query data, "" will be returned. It appears that
set tmp_filename [ns_queryget upload_file.tmpfile]
is setting tmp_filename to "" suggesting that upload_file.tmpfile "is not a key in the query data."

I lifted most of the code from /pvt/portrait/upload-2.tcl. What am I missing? -- Thanks.

Collapse
Posted by Dave Bauer on
Are you doing a POST? It looks like you need to for it to work according to the ns_queryget docs. Check out Answer 3 on the manual page.
Collapse
Posted by James Thornton on
Yes -- I am using POST:
form enctype=multipart/form-data method=post
Collapse
Posted by Andrei Popov on
Are you by chance running on WinNT? There are issues with binary files under it, you have to apply a patch to form.tcl found on SourceForge, but frankly, it still did not fix an issue for me.
Collapse
Posted by James Thornton on
Andrei - Thanks for your reply, but no, I am not running WinNT -- I am running Red Hat 6.2.
Collapse
Posted by Andrei Popov on
What does your upload.tcl (i.e. one step before) looks like? May it be that your form name for the <input type=file name=upload_file size=20> analog is not set to upload_file?