Skip to main content
September 8, 2010
Question

Accessing content of a file-upload via form.xyz directly

  • September 8, 2010
  • 2 replies
  • 593 views

Hi!

We're in the process of migrating from CF5 to CF9 and staggered over the following problem:

Consider a simple HTML form with a file-type input:

<form action="Something.cfm" method="POST" enctype="multipart/form-data">

   <input type="file" name="request">

   ...

</form>

On the server-side we accessed the content of the uploaded file via "#form.request#". Under CF5, the value of the form variable "form.request" was indeed the content of the uploaded file, as long as the file extension was ".txt", which lead to a "Content-Type: text/plain". Und CF9, the value of the form variable "form.request" is always the path of a temporary file on the server.

My questions:

(1)

Is there a way to tell CF9 that it should not create a temporary file and put the content always in the "form.request" variable n case the content is of type text/plain?

(2)

What is the use of the CFFILE tag in this context, if ColdFusion creates (temporary?) files for uploaded files by itself? I think I'm missing something obvious here...

Kind regards

Daniel

    This topic has been closed for replies.

    2 replies

    ilssac
    Inspiring
    September 8, 2010

    CLU42 wrote:

    I think I'm missing something obvious here...

    That there is a web server running between the client and the ColdFusion application server.  ColdFusion does not upload the file, ColdFusion has not direct connection with the client browser.  The actual flow is more like this.

    1. The Browser encodes the file selected by the user and puts it in the HTTP request.  This request is sent to the web server.
    2. The web server (IIS, Apache, etc) receives the request.  It decodes the file contained in the request, puts it in a temporary location.  Sees that the request is for a file type it has been configured to hand off to ColdFusion.  So it hands off the request, telling ColdFusion where the temporary file is.
    3. ColdFusion receives the request and starts processing the requested CFML code to process it.

    I suspect that when you jumped from CF5 to CF9, you may have also jumped web server versions.  And that is why the behavior is changing.  But I am not sure, because as far back as I can remember (CF 4.5) the file field of the form has always contained a location of a temp file.  But it has been a long time, so maybe my memory is faulty.

    September 8, 2010

    Thanks for your answers, ilssac & Adam!

    The behaviour that we have the content of the uploaded file directly in the form-variable is under CF5 with Apache 1.3 und mod_coldfusion.so. But as I wrote, only in the case where the uploaded file was text/plain. Anyway, now we know that this was more an accident than anything else. Actually it may make our file handler easier since we don't have to distinguish between text and binary files anymore.

    So basically, a cffile with action=upload is simply a move of a temporary file to a more persistant place. But since we're only interested in the content of the file during the request itself, I assume we can simply read the temporary file (with cffile and action=read) w/o uploading it first?

    Will try that tomorrow... thanks for your help!

    Regards

    Daniel

    Inspiring
    September 8, 2010

    If you ended up with the contents of the file in the form variable, that was aberant behaviour which has been fixed at some stage.  The way file uploads are supposed to work (and always have for me, since before CF5) is that one needs to use <cffile action="upload"> to move the file from the temp dir (the web server has to put it somewhere after all) to wherever you want the file to go.  Then if you need the file contents, you use <cffile action="read"> to get 'em.

    --

    Adam

    ilssac
    Inspiring
    September 8, 2010

    Looks like Adam agrees with my recollection that web servers have long sent a file location to ColdFusion.  If he agrees with my perceptions, that greatly increases my confidence in the memory.