isync has asked for the wisdom of the Perl Monks concerning the following question:

I use CGI::Fast in a C::A app. But when I upload a file, and use $q->tmpFileName to get the name of the temp file, it returns wrong values. According to the API of CGI.pm, it should return a path in /var/tmp/. But using CGI.pm in the fcgi wrapped variant CGI::Fast seems to change that. The real temp file resides in /tmp as /tmp/fcgid.tmp.some-id!

So it seems I can't access the temp file once my script runs in fcgi mode. Internally, CGI::Fast uses CGI + FCGI but I can't see where the swap in tmp paths happens.

Any hints? Is there a facility in FCGI I am overseeing that tells me the upload temp file location? Can I get the tmp file name directly from the (fcgid) env somehow?
  • Comment on CGI's tmpFileName does not work under CGI::Fast

Replies are listed 'Best First'.
Re: CGI's tmpFileName does not work under CGI::Fast
by afoken (Chancellor) on Apr 25, 2012 at 21:38 UTC
    According to the API of CGI.pm, it should return a path in /var/tmp/.

    Where does this information come from? Last time I looked, CGI.pm tried a hardcoded list of various locations: Re: On uploading a file, and I see no changes to that code in 3.59.

    The documentation is very clear on temp directory selection:

    The temporary directory is selected using the following algorithm: 1. if $CGITempFile::TMPDIRECTORY is already set, use that 2. if the environment variable TMPDIR exists, use the location indicated. 3. Otherwise try the locations /usr/tmp, /var/tmp, C:\temp, /tmp, /temp, ::Temporary Items, and \WWW_ROOT.
    Any hints? Is there a facility in FCGI I am overseeing that tells me the upload temp file location?

    Yes. Don't rely on any specific location. CGI.pm offers you a filehandle for each uploaded file (returned by the upload() method), and you are expected to read from that handle. Depending on the settings of CGI.pm (-private_tempfiles pragma), the file may have been unlinked before your program receives the handle, so the temp file no longer has a name. See also http://search.cpan.org/~markstos/CGI.pm-3.59/lib/CGI.pm#PROCESSING_A_FILE_UPLOAD_FIELD.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)