• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I use CFTHREAD in combination with CFFILE Upload

Contributor ,
Jan 01, 2008 Jan 01, 2008

Copy link to clipboard

Copied

I've been reading how CFTHREAD is supposed to release the client so that long-lasting operations like a CFFILE upload can continue to do their business while the client does something else.

How does this work exactly? I can't find any concrete references. For example, I have a regular file upload form. A user uploads a large file, say 100Mb, and I want to use CFTHREAD (or something) to handle the upload process, which I know may take hours depending on the connection, and immediately return the page for the client saying "Your file is being processed. Please check back later."

I tried wrapping some CFFILE code with CFTHREAD, but when I ran it the page just sat there working while the file was being uploaded, so I did not witness any change whatsoever in how its being handled. What am I missing?

<cfthread action="run" name="uploadVideo">
<cffile
action="upload"
destination = "/var/www/video1/assetsIN" nameconflict="overwrite"
filefield="video" />
</cfthread>

Thanks for any help.

UPDATE: I asked Ben Forta this in an email yesterday and here was his response:


What you are doing is correct. The actual file processing (getting the uploaded file) will not happen in a separate thread. Were you expecting a separate thread for the upload itself? CF can’t do that for you s CF does not have the file until it is uploaded. Actually, CF is not even called until the form is submitted (which includes the file being uploaded). It sounds like you want the browser to do an upload in the background. This may be doable using JavaScript and Ajax type controls. Or maybe using browser tabs or something. -Ben



Views

972

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 02, 2008 Jan 02, 2008

Copy link to clipboard

Copied

cfthread is the wrong approach. While it allows simultaneous activites within the same template, at some point all the activities actually have to finish before the template has finished processing.

In fact for files that big, ftp clients are a lot more useful than web browsers.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 02, 2008 Jan 02, 2008

Copy link to clipboard

Copied

With file uploads the time consumption is between the client PC and the web
server, not the web server and the CF server (which are usually on the same
machine). All <cffile action="upload"> does is copy the uploaded file from
the web server's temp upload dir to [wherever you tell it to go]: it's a
local process, and should be fairly quick; certainly compared to the
process of getting it to the web server in the first place.

Even if the data transmission was between the client PC and the CF server,
you can't expect <cfthread> to somehow increase the bandwitdh and speed up
the file upload between the two machines.

<cfthread> could come into its own if you had some file processing to
perform on the file *after* it's uploaded: unzipping it, doing some image
manipulation, parsing a CSV file into a DB, that sort of thing. Not for
the initial upload.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 03, 2008 Jan 03, 2008

Copy link to clipboard

Copied

> A user uploads a large file, say 100Mb, and I want to use CFTHREAD (or something) to handle the upload
> process, which I know may take hours depending on the connection, and immediately return the page for the
> client saying "Your file is being processed. Please check back later."

In order to achive this using pure server-side solution (CF only), you have to open two HTTP connections simultaneously. The first one will be busy uploading the file and no user feedback will be possible until the file arrives on the server in full (nature of HTTP protocol). Therefore, you need the second connection to display a message, continue interaction, etc. while the first one is unavailable. You could use iframe, pop-up window, or similar object in client's browser that is able to initiate the HTTP request.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 03, 2008 Jan 03, 2008

Copy link to clipboard

Copied

LATEST
Mr. Black, that's a good idea...to open a second connection somehow using iframe or separate window.

Actually, what I am now testing is use of Flex to provide this fucntionality, which can also display a nice progress bar while uploading. Flex can grab the file size BEFORE it gets uploaded. Super cool.

Here's the solution, with downloadable source code: http://www.asfusion.com/examples/item/file-upload-explained

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 03, 2008 Jan 03, 2008

Copy link to clipboard

Copied

The responses are clear on why cfthread won't help you here.
I think sometimes that we get trapped in trying to use ColdFusion for everything, when it may not be the best solution.

For 100MB files, I would investigate using FTP or similar alternative with some CF code to periodically check for uploaded files. Uploading 100MB via a browser would be frustrating at best when the upload fails at 97MB. This may not be an option either, not knowing what type of app or clients that you are dealing with.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation