Skip to main content
November 17, 2010
Answered

File Upload help

  • November 17, 2010
  • 3 replies
  • 3378 views

When a file is uploaded it:

1.       CF creates a unique temp name for the file.

2.       CF then starts uploading the file to the CF system temp directory using temp name.

3.       The file then sits there waiting for cffile to moved/renamed to directory specified in the cffile tag.

Is there a way to figure out the temp file name in #1 before #3 happens?

There has to be some system variable or something.

    This topic has been closed for replies.
    Correct answer Owainnorth

    cfjedimaster wrote:

    You can't do a file upload with Ajax. WHen you see that is actually a

    SWF doing it. (afaik)

    I want to upload in an iframe and have the parent ajax the status.....


    As has been mentioned, I really don't think this is possible as you'd have to intercept the data through IIS, all before CF even gets a look in.

    How large are these uploads that this is a major concern?

    3 replies

    WolfShade
    Legend
    November 18, 2010

    <cfset variables.fileInfo = GetFileInfo(GetTempDirectory() & GetFileFromPath(form["nameOfField"])) />
    <cfset variables.fileSize = variables.fileInfo.size /> <!--- gets file size --->

    <cfset variables.fileName = variables.fileInfo.name /> <!--- gets TEMP file name --->

    There's also an option for the full path to the temp file.

    ^_^

    November 18, 2010

    would this be known by an ajax request while the file is being uploaded?    

    November 18, 2010

    While the multi part form is posting, and the file is being written to the CF system temp dir (all this in a iframe), I want the parent to periodically run an ajax script and report back to the user the size of the temp file.

    I'm not sure if CF would be so kind as to allow an ajax request of the same session to learn which files his session is uploading.

    It looks like there are a lot perl scripts that do this, so I might post the form to a perl cgi script.  Then I can specify a temp directory and then in a mult-user environment everyone is writing to his own directory.  Then the parent ajax knows exactly which dir and file to check.

    So maybe my question should be along the lines of how to have perl and coldfusion interact to one another. 

    ilssac
    Inspiring
    November 18, 2010

    bmcgin wrote:

    When a file is uploaded it:

    1.       CF creates a unique temp name for the file.

    2.       CF then starts uploading the file to the CF system temp directory using temp name.

    3.       The file then sits there waiting for cffile to moved/renamed to directory specified in the cffile tag.

    I wanted to take a moment to clarify and correct what happens when a file is uploaded.

    When a file is uploaded it:

    1. The user submits a request with a file upload control.
    2. The browser reads the data from the file systems and encodes it into the request.
    3. The web server receives the request and decodes the file and places it in a temporary file location.
    4. The web server passes the request to the ColdFusion applicaiton server and tells it where the temporary file is located.
    5. The file then sits there waiting for cffile to moved-renamed to directory specified in the cffile tag.

    As you might see now, creating a file "upload' tracker is not a trivial task.  What are you going to track?  The time the browser takes to encode the file?  The time the encoded data is being sent from the client to the server?  The time the server is writing the file to its file system?

    These are lot of different systems inlvolved here and they are not very forth coming with API hooks to track this information.

    Inspiring
    November 18, 2010

    I think that the reason this topic comes up periodically is the misbelief that the file upload overhead (ie, transfer time) occurs at the time the CFFILE is procesed, which as Ilssac points out is incorrect - it happens before the webserver (IIS, etc) even starts the CF script.

    But this does bring up something that's always nagged at me because I couldn't figure it out:  How do file upload "progress" bars work?  I know some of them are just dummy progress meters that are cycling through an animated gif, but there are others that seem to be real-time based.  Where's the magic? What is the browser communicating with to know when the upload is complete?  If the CF script that runs does a zillion database queries that take up a lot of wall-clock time, does the browser think that that is part of the upload time (because barring the use of CFFLUSH, I don't think that IIS is going to start sending a response back to the browser until the CF script completes)?

    Curious,

    -reed

    ilssac
    Inspiring
    November 18, 2010

    Reed Powell wrote:

    How do file upload "progress" bars work?

    The only ones that I am aware of, that are not "dummy progress meeters," involve using Active X, Java, Flash, or some technology that interceedes between the browser and the web server to manage the file upload process.  These tools create true two way communications (which normal HTTP is not) between the client and the server and can do things like this.

    cfjedimaster
    Inspiring
    November 17, 2010

    I believe if you output form.thefile (where thefile is the field name)

    you see it.

    November 17, 2010

    By the time you dump the form, the temp file has been fully uploaded to the temp dir.

    In another ajax request, while the file is being uploaded, I want to check the size of the file and then report the progress back to the user. 

    So I need to find the mapping between the system file and form.file as it’s being uploaded.

    November 17, 2010

    Another solution would be to be able to set the CF temp directory before uploading the file.  Can this be done?