Skip to main content
Participant
September 15, 2006
Question

Code before CF writes client file to disk

  • September 15, 2006
  • 2 replies
  • 771 views
Can I write some CF code and <cfflush> it out before CF tries to process form values or at least before it tries to write a client file to disk?

Here is the situation:
A form has a file input element so that the client can upload a file. Sometimes it takes a while (several seconds) to upload the file. The majority of the time is waiting for CF to write the file to a temp directory. I'd like to write some CF code that will execute before CF tries to process the form values and puts them into the form scope -- or at a minimum, before it tries to write the client file to disk in the tmp directory. The output I'd like to produce would be an animated gif and some text. Here's an example of the flow I would like to have:

* Form is submitted by client
* *** special *** generate some output and flush it out to the client (maybe via an "undocumented" file, 'preFormProcess.cfm' -- similar to 'application.cfm'. This must occur before CF tries to put the form values into the form scope, or at least before it tries to write the file to disk in the tmp directory.
* Then, have CF do it's normal thing, process the form fields, stream the file to the tmp directory
* execute the normal cf code

I can do this in C/C++ because I can determine when I read the form data that was posted (via standard input), but I don't see any way to do this in ColdFusion, because it automatically processes all the form values, and automatically writes any uploaded files to disk, before I can have any of my code execute.

Please let me know if there is any way to sneak in my code before CF automatically processes the form data.
Thanks!
This topic has been closed for replies.

2 replies

Participating Frequently
September 16, 2006
This is not possible regardless of programming language (including C/C++). This is by definition of HTTP protocol. You cannot reply to the client using the same HTTP (TCP) connection until entire client's request is consumed by the server.

If you want to perform some activities on the client side while HTTP request is processed, you have to do it entirely on the client side (JScript, Flash, ActiveX, Applet, etc) or by utilizing another HTTP connection. This is how upload monitors work.

Resume: there cannot be any "simple" <cfflush>-like solution.
Inspiring
September 16, 2006
You can do exactly what you described in the first paragraph, well, I can. What did you try and what went wrong?
mike__jAuthor
Participant
September 19, 2006
If I have a form, a.cfm, where a file can be uploaded, and posts the data to b.cfm, I can't even <cfflush> 'Hello World.' until the file is completely written to the tmp directory by ColdFusion. This can take 30 seconds or more if the file is big enogh or the connection is slow. Thus, the user sees no change on the screen until their file is totally uploaded. Note that this is done automatically by CF before even 1 line of my code is executed. I want to give the user some response before the file is totally uploaded by CF to the tmp directory. What I'm asking is this: Can I <cfflush> any output before CF writes the entire file to disk?

I can do this using another language such as 'C', where you can control when you open the input stream and start reading the file. In C, I can flush out some output, in order to give some response to the user, then read the input stream later. In fact, in C, I can totally ignore the input stream if I want to. The problem I'm having is that ColdFusion automatically reads the entire input stream (and makes all the Form variables, etc), before it executes any of my code. What I need to do is have some of my ColdFusion code execute before ColdFusion automatically reads the entire input stream. Is there any way to do this in ColdFusion?

I know that I can use other client side tricks, like hidden iframes, javaScript and the like to entertain the user while the file is being uploaded. That's not what I'm looking for. I'm looking for a solution to the ColdFusion issue. I hope the description of the problem makes more sense now.
September 19, 2006
As already stated, you cannot do this in C or any other language with a simple form.
Read the html specs starting at http://www.w3.org/TR/html4/interact/forms.html#h-17.13.3.4

The BROWSER sends all of the file information as part of the post.
This is not a CF issue. It's how html and all browsers work.

You must use client side tricks like staggered submit or rolling your own upload client to get any more user feedback.

If you say you can do this in C, then (1) prove it here and then (2) call that C snippet from CF or the client's browser (problem solved).