Aug
08

File Upload with ColdFusion Flash Forms

364 comments Posted by: Laura

File Upload with cfform
At last! File upload was, in my opinion, one of the most important missing features for Flash RIAs to be taken seriously. One of the reasons we couldn’t reproduce HTML forms with Flash CFForm was the file upload. But now that the new Flash Player has file I/O features, we can use it to incorporate them to Flash forms, and make it even better than regular file upload, with more user feedback such as progress bars. As you may expect, you need the Flash Player 8 to run this example. In the zip file you will find a custom tag, an example, and a swf file.

We have implemented most of the I/O methods provided by the new API, and use them to add a progress bar and some progress information such as percentage and total bytes uploaded.

The custom tag consists of two tags, an enclosing cf_flashUpload, and an inner tag, cf_flashUploadInput.

This is the simplest example on how to use the custom tag, with default values:

<cf_flashUpload name="defaultInput" actionFile="upload.cfm">
   <cf_flashUploadInput />
</cf_flashUpload>

A more complex example would be:

<cf_flashUpload label="Picture" name="myFile2" fileTypes="*.jpg;*.png;*.gif" fileDescription="Image files" actionFile="upload.cfm">
   <cf_flashUploadInput buttonStyle="corner-radius: 0;" inputStyle="fontWeight:bold" inputWidth="80" uploadButton="true" uploadButtonLabel="Upload Label" chooseButtonLabel="Choose file" progressBar="true" progressInfo="true" />
</cf_flashUpload>

flashUpload Usage:
Attributes:

  • name: Required; Name of the text input that will contain the name of the file to upload
  • actionFile: Required; File that will handle the upload. It can include query string variables to identify this file. Example: upload.cfm?id=15
  • label: Label to put next to the control.
  • fileTypes: extensions to accept, separated by semicolons. Example: *.jpg;*.png;*.gif
  • fileDescription: Text to describe accepted files
  • maxSize: maximum file size in Kb to upload. Defaults to no limit
  • swf: name of the swf file that contains the i/o libraries. Only needed if your swf is not in the same dir as your cfform

flashUploadInput Usage:
Attributes:

  • inputWidth: with of the text input where file name is shown
  • buttonStyle: style applied to choose and upload buttons
  • uploadButton: true/false, default true. Adds an upload button. If you set it false, you must put the generated variable called “theNameOfYourInput_uploadScript” in some other button (“theNameOfYourInput” is the name assigned in the flashUpload tag name attribute)
  • progressBar: true/false default true. Adds a progress bar.
  • progressInfo: true/false default true. Adds an output area to show progress info
  • progressBarStyle: style of progress bar
  • uploadButtonLabel: label of “Upload” button
  • chooseButtonLabel: label of “File browse” button

Notes on error codes:

404: As you may know, 404 means "file not found". As such, it means that the address you are sending the upload to does not exist or it cannot be found by the web server. You will need to make sure you are pointing the "actionFile" attribute to the right place. When in doubt, try using an absolute path (ie: /myuploads/directory/upload.cfm)

500: This error could be due to many things, but it is an "Internal server error". Issues to check:
- You are uploading files larger than the allowed post size set in the CF administrator. See the setting "Maximum size of post data" in the Settings page of the CF administrator. The default I think is 100MB
- You are uploading large files and CF is running out of memory. CF has to put the whole size in memory while it gets uploaded before it saves it to disk. If you have access to the logs (the java output logs, not the regular cf logs), check for this error.

A couple of notes from the comments:

Posting additional data: handling a file upload posted by Flash is different than handling an upload posted by an html form. The first difference is that you cannot specify the name of the file input, it will always be "FileData". The second difference is that when you trigger the file upload, you are only sending the file contents and the file name, but cannot send anything else, whether it was in the form you have or not. That is, on your "form" scope in upload.cfm, you will only see those two fields. The only data you can send is what you append to the upload action file name query string (ie: upload.cfm?variable1=test), and you will get that in the URL scope of upload.cfm.

Getting data back from the upload action page: The only things you will get from the upload action page are HTTP status codes. 200 will mean the upload was successful (or that at least there was no server error). If you change the file name, make a query to retrieve anything (ie: an id), you will not be able to send that back to the calling page. You can do any of that, for example if you wanted to send an email after a file was uploaded, or resize the image you uploaded, as this is a normal cfm page, but you cannot communicate any of this to the calling page.
An update on this: If your user is running player 9.0.28, you could get information back from the upload action page. You will have to, however, change the .fla that implements the uploading. See the docs.

View live example (please be gentle with our bandwidth)
Download the source

Category: CFForm | ColdFusion |

364 Comments so far

Write yours
Joshua Dale
1. Joshua Dale wrote on August 08, 2005 at 1:23 PM
Sweet, this is the only thing keeping me from using flash forms in my site.
Steven Ross
Its about time, I was wondering if this would be possible with the new addition of I/O in player 8. Thanks for working on this! I see a patch coming for Coldfusion.

Joshua Dale
3. Joshua Dale wrote on August 08, 2005 at 7:05 PM
You would hope so until you go into livedocs and read "this bug will be fixed in the next release"

I just want them to take the size limit off of their flash forms, there is no reason it should be on there and there is no documentation saying there is.
Todd
4. Todd wrote on August 08, 2005 at 7:47 PM
Has anyone else noticed flash forms run extremely slow in flash 8? It was so bad I had to uninstall and go back to 7. :(
Nahuel
I haven't found the player to be slow, actually it's faster for me. Did you check different flash forms? any in particular?
Maybe you can submit a bug about this.
Joshua Dale
6. Joshua Dale wrote on August 08, 2005 at 9:06 PM
It feels faster to me also, although the upload app seemed a little slugish, but it is in beta right ;o)
Joshua Dale
7. Joshua Dale wrote on August 08, 2005 at 9:08 PM
I do have one question though, how do you create custom tags for flash forms??? Is there an article you can point me to?
Trond Ulseth
Is there a way to display the uploaded file when it is uploaded - provided it is a image file?
M. Schopman
9. M. Schopman wrote on August 09, 2005 at 7:16 AM
Is the limitation of not being to resize the browse dialog (missing resize handle in the corner) defined by the IO functionality in Flash 8? If so that is bad :)
Doug Hughes
Is there any chance this thing has a way to prevent users from uploading files over a certian size?

Thanks!
Joshua Dale
11. Joshua Dale wrote on August 09, 2005 at 9:47 AM
Yea, it is the 3rd one down. It has a max size of 200Kb.
Joshua Dale
12. Joshua Dale wrote on August 09, 2005 at 10:13 AM
Does a copy of the swf file need to be in the same folder as where the custom tag is being called?
I don't seem to be able to get it to work otherwise.
spiraldev
13. spiraldev wrote on August 09, 2005 at 10:14 AM
Where can I get flash player 8?
Joshua Dale
14. Joshua Dale wrote on August 09, 2005 at 10:17 AM
Laura
Joshua,
There is an attribute called swf in the flashUpload tag where you can tell it where your swf is located. I only used it with absolute path (ie: /blog/examples/fileUpload.swf) but I believe it should work with relative path too.
Joshua Dale
16. Joshua Dale wrote on August 09, 2005 at 3:35 PM
Yea, I noticed that right after I posted... I guess it helps to read the instructions first ;o)

Thanks for the response though.
Trond Ulseth
Joshua, when you said:

You would hope so until you go into livedocs and read &quot;this bug will be fixed in the next release&quot;

... what exactly are you talking about. Will something be &quot;taken away&quot; from us?
Joshua Dale
18. Joshua Dale wrote on August 10, 2005 at 6:45 AM
Oh no, I was just joking...

It seems whenever a bug is reported in livedocs, the developer says it will be fixed in the next release of ColdFusion.
This behavior has always bothered me, but now I am in the ColdFusion MX 7 Updater Beta program so things are looking up.
No
19. No wrote on August 10, 2005 at 3:45 PM
Good to see Flash has hit the 20th century. Congrats to all those involved in bringing a product to a level it should have been at 15 years ago. Woopy doo!
Brian Sloan
20. Brian Sloan wrote on August 11, 2005 at 7:04 AM
I posted this in the mxna comments but since this thread is more active here it is again... Any help would be greatly appreciated.

Strange problem:

I am adding data to a table using remoting and I get the following error (from handler.onStatus): &quot;Error while calling cfc: Service app.services.facade does not have a method addData that matches the name and parameters provided.&quot; However it adds the data correctly. Here is what I am doing... In the facade file I have a addData function that looks for the arguments method (string used in switch statement to determine what function to call in another cfc) and fields (structure that hold all fields passed in). Then I have an action script function that is pretty much exactly like the one in this example to call the facade function. In my cfm file, on the click event I call the as function with following code:

_global.addRecord({
gridName:myGrid,
method:'addContract'
fields:{
idn:selectBox.selectedItem.data,
number:number.text,
(etc....)
}
});

Any ideas??? Is there a problem with my fields structure? I am trying to make the facade function more dynamic by passing a structure instead of individual args... Like I said it is inserting the record correctly just throwing that error... So it is running the function or the row wouldn't be added... What causes the handler.onStatus section to execute? I am trying to returning a result to get the primary key of the added record, but it is running the cfc function and return a status instaed of the result.

Thanks,
Brian
Michael Tyler
Any way to have multiple form fields and one Upload button?
Brian Sloan
22. Brian Sloan wrote on August 11, 2005 at 8:04 AM
got it working now... error was in the variable I was returning...
Laura
Michael,
Look at the last example in the zip file, where you can trigger the upload from any other button you choose. If you want to trigger multiple uploads, just keep pasting the generated variables (theNameOfYourInput_uploadScript) in your onclick of the button of your choice.
Phil
24. Phil wrote on August 11, 2005 at 5:49 PM
Is there a way to use other input fields like &quot;My File Name&quot; and one buttom that triggers upload and submit of other form fields?
Michael Tyler
25. Michael Tyler wrote on August 12, 2005 at 10:58 AM
Laura,
I cant get a working example of having multiple file upload fields and one submit button.
Do I just add more <cf_flashUploadInput> tags?
I would like to end up with having 5 files fields and one button to do the action.
Mic
26. Mic wrote on August 12, 2005 at 11:43 AM
nm , I got it. Dang Typos always kill
me.
Rick
27. Rick wrote on August 13, 2005 at 1:54 PM
If hit choose file or browse it does not do anything
Nahuel
Rick,
You need the Flash Player 8 to run this example
Nahuel
Trond,
We made a new post showing how to show a picture after uploading it
http://www.asfusion.com/blog/entry/showing-an-image-after-upload
Maria Kang
30. Maria Kang wrote on August 14, 2005 at 12:27 AM
It is good, because i am finding the solution on upload file in cold fusion.
I am also find the solution on how to update the upload file. Do you have the solution on that?
thank you!
Joshua Dale
31. Joshua Dale wrote on August 15, 2005 at 8:27 AM
Is there any way to keep the buttons from wrapping around?
Michael
32. Michael wrote on August 15, 2005 at 10:53 AM
Is there a way to change the destination folder of the uploaded file? I can not seem to figure out what expandpath is.

Thanks.
Paulo
33. Paulo wrote on August 16, 2005 at 5:30 PM
In my application is ocurrency this error message:

Invalid content type: "application/x-www-form-urlencoded".

CFFILE action="upload" requires forms to use enctype="multipart/form-data".

how can finish this problem?

Thanks
SaeedR
34. SaeedR wrote on August 23, 2005 at 11:09 AM
From my perspective everything looks ok; I'm able to open a file browser, select the file and even upload. The progress indicator runs but I continually receive an &quot;HTTP Error number:500&quot;.

Anyone have any ideas?
steve
new to flash but I need to create a flash form to upload a image and connect it to a reference number then has another form that will let me conduct a search of the image connected to the reference numbers stored.
any help will be appreciated
also I need to see how I could stop people from printing my pictures from my swf file and xml www.theassociates.tv
thank you
Matt Gifford
Hi guys.

This is a great script, thank you so much!

I have just integrated the tag into my cfform and it's browsing for the file which is great!

Please could someone tell me if/how you can alter the buttons and input so they dont wrap? I would like to try to get them to merge into the rest of the form without looking like it's been placed on top.

Many thanks,
and keep up the great work!

Matt
Laura
Matt,
you can try specifying the width of the text input until it doesn't wrap.
<cf_flashUpload ...>
<cf_flashUploadInput inputWidth="150" />
</cf_flashUpload>
Matt Gifford
Thanks Laura! :)
NRR
Can it truly upload multiple files i.e. not multiple file inputs but the ablity to select more than one image then click upload and upload them all one after the other? An example would be great.
Laura
Michael,
To change the destination folder just write your desired absolute path in the destination attribute (without the #s). expandpath is just a shortcut to get the current directory path. I used that so that the example would work as is when downloaded.

Paulo,
You are using the regular html form with input type="file", if you are, then you need to write
<cfform enctype="multipart/form-data" ....>

SaeedR,
Your upload action page has a problem. You need to check it, It could be either not even compiling (can you even browse that file without getting errors?) or not working with the data you are sending to it. I would recommend that you make a test with a regular html file upload to see what the problem is, then when all fixed, make the change to flash forms.

NRR,
yes, that can be done. We'll make an example when we get a chance.


Pegarm
Is there a way to cause the form to submit once the upload action is completed?
Daniel Smith
42. Daniel Smith wrote on August 30, 2005 at 2:42 PM
Pegarm,

Yes, I added "_root.submitForm();" in the onComplete listener. See my example below:

<cfif attributes.progressInfo>uploadListener.onComplete = function()
{
output.text = "Upload complete";
_root.submitForm();
}
</cfif>
Matt Gifford
Hi All.

Is there any way to change the location of the action page in your script (the upload.cfm page)?

I think I may need to specify another page to run as the action page instead to get the results and extra queries that I need, but I cannot seem to be abel to find where the upload.cfm page is specified in the code.

Any help would be greatly appreciated!

Many thanks
Matt Gifford
I'm really thick! I found the action page in the form (I forgot it was there!)

Sorry! :)
Seth
45. Seth wrote on September 05, 2005 at 1:06 PM
My upload script always fails with an IO Error when upload from a network location (UNC path on windows). Is this a problem with the beta, or a security &quot;feature&quot;.
Asher Gilbert
There's a slight bug in that although the file selection dialog filters to a file type, it does permit *.* as a search term, and so any file type can be uploaded.

Also, is I cancel the file dialog but then choose to 'browse...' again, all the listeners fire twice on each event. The listeners fire as many times as you've had the browse dialog open.

This needs to be improved.

Great job though
Matt Gifford
hello.

Please can someone tell me if I can enable the upload button to be active at all times, instead of only being displayed if a file has been selected in the browse section?

many thanks
Matt Gifford
Hi.
I am sooo almost there with what I needed this form to do. Only one thing holding me back now, and I would really REALL appreciate help on this one (my job may depend on it..)

The actionfile uploads the files, and makes unique in case of duplication.
In my form, the form data is then inserted into a database to store the filename and location on server.

However, if the file was renamed using cffile, the new &quot;unique&quot; filename is not being transferred to the database, just the original filename in the input box.

Please please please does anyone now how I can change this so that if the file is renamed on the server side, the new name is sent to the database?
I tried cffile.serverfile, but as the actionfile is a separate page, I dont know how to transmit that data to the form action page that inserts data into the database.

Please please please?
Laura
Seth,
That certainly seems to be a bug.

Asher,
I haven't seen that behavior. I'll ask Nahuel if he can take a look. Regarding the *.* search, is this in Windows? I can't make the search dialog appear in Windows and it works fine in Mac.

Matt,
To enable the upload button all the time, set disabled=&quot;false&quot; in line 128 and remove lines 69 and 75.

As of now, there is no way to send data back to the calling page.
You will have to make sure the file you are uploading does not get renamed. I usually do that by sending a unique id and naming the file with it.
SaeedR
50. SaeedR wrote on September 12, 2005 at 9:29 AM
Weird ... I'm all of a sudden receiving the &quot;IO Error&quot; whenever I try to upload, too. I'm not using a network share, however. Any idea what the bug might be resulting from?

(Thanks much for the response earlier, too.)
George
I got this all working fine. But I want to send info like 5 fields to a DB. I put the fields in the form and am using the trigger by another button. But im not sure after that. I have tried to put my INPUT satement in the Upload.cfm page but that does not work. Is there a sample somewhere? As soom as I put the INPUT in the action.cfm page it doesnt upload the image or the form fields. Can anyone help? Thanks
nigel king
52. nigel king wrote on September 15, 2005 at 3:26 PM
Does file upload work, on a mac?
I have the prerequisite versions of browsers and OSX, every example i have found on the web (~8), and written myself, throws an IO error.

All work fine on WINXP IE,Netscape etc. I am however running OSX under PEARPC (poor developer, and this customer only has macs), is this my problem?
Next step tracing the network!
Nahuel
Nigel,
Yes, this work on mac, but only on OSX.
Make sure that the machine has the latest player( 8 ) installed
Steve
54. Steve wrote on September 18, 2005 at 9:41 AM
Here it is what's in the fla file:

// Action script...

// [Action in Frame 1]
function addListener(listener)
{
imageFile.addListener(listener);
} // End of the function
function browse(list)
{
imageFile.browse(list);
} // End of the function
function upload(path)
{
return(imageFile.upload(path));
} // End of the function
var imageFile = new flash.net.FileReference();
Luke Crawford
55. Luke Crawford wrote on September 19, 2005 at 7:37 PM
Awesome article! Thanks for showing how this is done. I've already looked in the Flash 8 developer docs for my one remaining question and I'm hoping somebody has the insight. Is there any way to create a drop target so a user can drag a file(s) from their desktop (Finder/Explorer) onto the Flash app instead of selecting the file from the browse dialog? Thanks if you can point me towards this!
Nahuel
Hi Luke,
Drag and drop from the desktop to the browser is something that flash does not support yet.
Matt Gifford
Hi all.

I have been having a nightmare today with the code.
It has worked fine until today when I noticed an error being generated.

If I try to upload a file over my production server, I receive a securitySandboxError message in the form.
However, if I try on my localhost server, the upload works.

Does anyone know of any discrepancies with the Flash Player that could have caused this?
I have checked the Sandbox settings on my server, and they arent even turned on, and it looks as though everything is as it should be.

Many thanks
Mode
How can you get the file to rename with a random number. it is throwing an error when i try and rename the file.
Laura
Matt,
That seems to happen when you try to upload to a domain different from where the swf is. Otherwise, I don't know what it may be causing it.

Mode,
Check this post as an example of renaming the file:
http://www.asfusion.com/blog/entry/showing-an-image-after-upload
James
60. James wrote on September 25, 2005 at 2:21 PM
I have included uploading a file into my form. How do I make it required like I can a input field?

Thanks
Noel
61. Noel wrote on September 29, 2005 at 3:16 PM
I must be an idiot, but I can not get it to work at all! (page is not even loading!)

I'm new to MX7, and have no clue what I'm doing wrong.

Does the demo file from above 'download the source' work straight out of the box, or do I need to add some extra settings? (like custom tag info).

MX7 is running on a Linux server, and I do understand that I have to CHMOD some dir's, but again.. the site (index.cfm) does not even load! (other sites do)
Noel
62. Noel wrote on September 29, 2005 at 4:00 PM
(ex)Idiot here..

I found the problem..
The 'Default CFFORM ScriptSrc Directory' in my MX7 &amp; linux setup was set wrong!

After playing with it, I got it to work..
Shivang
63. Shivang wrote on October 03, 2005 at 6:52 AM
Hi All,

This is a question that is not directly related to the upload of a file but to "Force a Download of a file". I have it working outside the flash forms but within the flash form if I have a link to a file type of (doc,ppt,zip, etc any file type). In IE 6.0 it does not show me the screen where it asks you "Do you want to open or save this file etc. etc. But instead it the browser shows an error saying "Action canceled
Internet Explorer was unable to link to the Web page you requested. The page might be temporarily unavailable." If I reload the page I get the Dialog box "Do you want to open or save this file". ANy idea why this is happening only in Internet Explorer and not Firefox and Netscape. Any ideas on how to force a file download from flash forms is appreciated. Thanks a lot
Jason
64. Jason wrote on October 03, 2005 at 3:34 PM
Anyone try it on fusebox app? Can't figure out what is the path.
Tony
65. Tony wrote on October 04, 2005 at 2:48 AM
I've tried it in FuseBox and can't get it to work, with a relative or an absolute path. I can include the swf using the path, but the same path won't work within the cf_flashUploadInput. weirdness
Noel
66. Noel wrote on October 04, 2005 at 8:27 AM
I'm trying to make the 'uploader' to go to the next page when uploading is done.

I have tried by adding the following in the uploadListener.onComplete = function()

<!--- start added stuff for redirect --->
getURL("http://www.domainname.com";);
<!--- end added stuf for redirect --->

The getURL does not work :-(

Anyone here who might have a hint, on how I can get this done?
Laura
James,
>How do I make it required like I can a input field?

I updated the custom tag to allow for required and message attributes (to be added to flashUploadInput inner tag). However, if they write something into the text field, it will validate even though it was not uploaded. You will have to do something fancier for that or even disable the field (but that's not included in the tag)

Shivang,
> In IE 6.0 it does not show me the screen where it asks you "Do you
> want to open or save this file etc. etc. But instead it the browser
> shows an error saying "Action canceled

I don't know, this is working for me in both browsers:
<cfformitem type="html"><a href="myfile.zip">Download zip</a></cfformitem>
You might want to check your web server.

Tony,
> I've tried it in FuseBox and can't get it to work

I can't really help you with the info you provided. Paths are the same as if you would browse the file with your browser, be it a swf, or a cfm. If it works in your browser it should work here, although absolute paths are preferred.

Noel,
> The getURL does not work

Use _root.getURL("http://www.example.com";);


Erik,
> I am unable to get it to work as I am unable to designate the
> enctype to multipart/form-data

This is not using <cfinput type="file"> therefore it does not need the form-urlenconded format. If you are using this tag, hence a flash form, it should work as is. Download the example and try to run it to see if it works for you. The other person *was* using cfinput type file in a regular html form and that is why he needed the encoding type. If you want to know how this tag works, check
http://www.asfusion.com/blog/entry/file-upload-explained-and-expanded
Jason
68. Jason wrote on October 05, 2005 at 6:31 AM
Hi Laura,
FYI, I'm using FuseBox MVC
all the files (upload.cfm ,flashUploadInput.cfm, flashUpload.cfm, fileUpload.swf) are in the /view/pages

I change the path as follow:
<cf_flashUpload actionFile="view/pages/upload.cfm">
and
<cfparam name="attributes.swf" default="view/pages/fileUpload.swf">

It shows "HTTP Error number:404"
when the progressBar done uploading

Did I miss out anything?
Mizuno
69. Mizuno wrote on October 05, 2005 at 12:29 PM
I can run the example on the site, but when I download the code and try to run it on my server nothing heppens when I press the browse button. Am I missing something here?
Laura
Jason,
If you use relative path for the actionFile, it will be relative to the location of the swf, so I think in your case it should simply be upload.cfm. I would recommend though that you use absolute paths ("/your/path") to avoid any confusion.

Mizuno,
If you have Flash Player 8, there shouldn't be a problem. I suggest that you check whether the form is able to load the fileUpload.swf file.
Mizuno
71. Mizuno wrote on October 05, 2005 at 2:11 PM
Laura:

I do have Flash Player 8...downloaded it for this purpose. I have not used an .swf with a Flash Form before so I am not sure what to look for as far as whether it is loading correctly or not. Any help is appreciated.

Thanks
Jason
72. Jason wrote on October 05, 2005 at 2:26 PM
No luck still...
I've been trying absolute and relative path for both, same error keep showing up at the end of uploading.

I tried all:
actionFile=/view/pages/upload.cfm
actionFile=view/pages/upload.cfm
actionFile=upload.cfm
actionFile=http://#cgi.HTTP_HOST#/myapp/view/pages/upload.cfm

Thanks!
Laura
Mizuno,
You can use this extension in Firefox http://livehttpheaders.mozdev.org/ or Fiddler for IE to see if the file is called and it doesn't get a 404
Laura
Jason,
I don't know what the problem is. Try using Fiddler (LiveHttpHeaders does not show the Flash form post) and see what file is calling and why it is getting a 404.
Erik
75. Erik wrote on October 08, 2005 at 9:48 AM
HI Laura, Thanks for the response.

THe problem is, I am not declaring any enctype, and it still throws that error. I too am using Fusebox but i doubt that would have anything to do with it. I will continue to fiddle with it. Best,Erik
Brett
76. Brett wrote on October 10, 2005 at 2:31 PM
I can do a CFFILE upload without any errors at all. When I use this custom tag inside a flash form, I get prompted for logon credentials every time, even though I'm trying to upload to the exact same location. Even stranger, is that no matter what credentials I use (including the local administrator account), it fails with a 401 error. Any ideas?
Chris Albutt
77. Chris Albutt wrote on October 10, 2005 at 4:48 PM
Hey guys,

Got everything working fine on my local dev environment, upload to live environment and I get a Javascript error

When I run your demo source code I get the same error -
Line: 29
Char: 1
Error 'lc_id' is undefined
Code: 0
URL: ...

Anyone shed some light on this?
Shivang Patel
78. Shivang Patel wrote on October 11, 2005 at 6:09 AM
Chris Albutt:

I had the same problem some time back when I used this example. What you need to do is in the CFAdmin "Default CFFORM ScriptSrc Directory" Make sure that the path to the scripts directory is correct. I have it deployed on WebLogic and my path was all messed up and was getting the same error lc_id not defined. If you have given a context root then It needs to be there in the path. In my case I have / as my context root so this is what my path looks like: /CFIDE/scripts/.

Hope this helps..
Daz
79. Daz wrote on October 12, 2005 at 5:57 AM
I want to upload a file as well as passing other cfform data to be written to a database.

how do i integrate the file upload element with other cf form elements.

essentially i want to upload a file an pass that files name and other form values into a database via remoting?
Laura
Chris,
I never experienced that problem but I heard it happens if the browser cannot access the cfide/scripts file. Check that you are able to browse the files in that directory.

Daz,
Check this post:
http://www.asfusion.com/blog/entry/showing-an-image-after-upload
You can have the file name in a hidden field and then send all the form items by submit or via remoting.
Steve
81. Steve wrote on October 14, 2005 at 3:26 AM
Hi,

I keep getting an IO error on larger files. By large I am talking about greater than 150mb. No slow down of upload real pattern appart from more than 64mb. I have watched the server and nothing seems off there either, the upload just seems to stop.

Help!
Steve
82. Steve wrote on October 14, 2005 at 4:08 AM
I have some more information that might help. It apears that the upload will fail at 64mb intervals. If I watch the input to the server durring an upload i can see a conanstant bytes per sec in at around 1058028. At 64mb, 128mb the upload flash will stall, maybe for a few seconds. The result is that the stream is interupted and lost. following on the flash routine will continue for a while and then error with an IO error.

So what is causing a pause every 64mb?

Coldfusion mx7 Enterprise (windows).
Firefox and IE

Thanks

Steve

Daz
83. Daz wrote on October 14, 2005 at 4:48 AM
Thanks Laura,

Is there any examples of sending via remoting as opposed to receiving, as the only posts I can see all talk about receiving.

Thanks For Your Help

Daz
Mizuno
84. Mizuno wrote on October 17, 2005 at 11:56 AM
I am able to upload files using this code...Thanks for the great code!

However, when another user (non admin) tries to upload they receive a 401 error. I have opened it up to them as far as I can and they still get the error. They can directly save to the folder, but cannot save via the upload process. They are asked to authenticate each time they try to upload a file but receive the 401 error even with proper credentials.

What I would prefer to do is to have the repository for uploaded files to reside on another server. This would allow me play around with rights a little more as far as who can write to the folders, etc. I have given an example directory structure below and under it pose some facts and questions.

SERVER1
=======
root
..level1dir1 (documents)
..level2dir1 (department)
..level3dir1 (office)

SERVER2
=======
root
..level1dir1
..level1dir2
..level1dir3 (inetpub)
..level2dir1
..level2dir2 (wwwroot)
..level3dir1
..level3dir2
..level3dir3 (intranet)
..level4dir1
..level4dir2 (documents)
..level4dir3
..level4dir4 (upload folder)

1) Upload intranet site resides on SERVER 2 in the 'upload folder'.

2) Using code 'As Is' results in file being uploaded to 'upload folder'.

3) Altering UPLOAD.CFM by changing 'destination="#expandpath(".")#"' to 'destination="#expandpath(".")#/../level4dir2"' results in files being uploaded to documents directory on SERVER 2.

Q1) How do I change this line of code to specify a location on another server as the repository for uploaded files? i.e. I want the files to be saved to SERVER 1 into folder OFFICE.

Any help will be appreciated.
Mizuno
85. Mizuno wrote on October 17, 2005 at 11:58 AM
for above post....spaces were omitted in directory structure.

SERVER1
=======
root
..level1dir1 (documents)
....level2dir1 (department)
......level3dir1 (office)

SERVER2
=======
root
..level1dir1
..level1dir2
..level1dir3 (inetpub)
....level2dir1
....level2dir2 (wwwroot)
....level3dir1
....level3dir2
....level3dir3 (intranet)
......level4dir1
......level4dir2 (documents)
......level4dir3
......level4dir4 (upload folder)
Stuart
I really like this, it's just what i've been needing. And from a design point of view I love the colours used.

Just my problem is that i'm on a co-hosted site so i don't have a cf-tag directory but i'd like to use the cfmodule. Should this be how I am referencing it:

<cfmodule template="/webs/02005/cftags/cfform_fileUpload/fileupload.cfm" name="cf_flashupload">

In this sort of way?
Stuart
Sorry, the cfmodule i wrote should have pointed to flashupload.cfm - but still i can't get it to work.
Stuart
Hi,

I managed to get it to work but i had to have my CFTAGs in the same directory as where my form was.

Anyhow, i'm on to a new problem now. I am trying to insert a query on the upload.cfm page. Should this be possible?

<cfif structkeyexists(form,"Filedata")>
<!--- upload file with whatever attributes you need, additional variables may come in url scope --->
<cffile action="UPLOAD" filefield="Filedata" destination="#expandpath(".")#" nameconflict="MAKEUNIQUE">
<cfquery name="AddImage" datasource="user020">
INSERT INTO tbl_020eventImages (eventID)
VALUES (#form.eventID#)
</cfquery>
</cfif>


Should this be possible to add the value #form.eventID#? eventID is a field which is also in the form where my cf_flashupload tag is.

Should upload.cfm be able to receive the parsed form variables?

It's saying error 500 in the progress bar after it's finished uploading. It's fine without my query. After testing it appears it can't read #form.eventID#. But should it?

Any help i'd be very grateful.

Thanks,
Jason
89. Jason wrote on October 19, 2005 at 10:58 AM
Has anybody gotten this to work inside of an applcation.cfm protected directory?

It was working fine outside of my password protected area, but when I move the code over behind a login framework, I get the log in form displayed (which I discovered through Fiddler) -- the file never gets uploaded.

I think maybe the .fla file doesn't authenticate or something maybe? I'm not sure! :o
Nahuel
Jason,
This is a bug from the flash player. As far as we know, it only happens in firefox. You should submit a bug to Macromedia, we have already reported it but they will be more likely to fix it if a lot of people request it.
Laura
Stuart,
It is not possible to send any form variable directly to the upload action page. Only url variables are allowed (appended to the action url). Check this example (with filename renamed) to see how to do it: http://www.asfusion.com/blog/entry/showing-an-image-after-upload

Jason,
When we first encountered the problem I tried a workaround that didn't work. For some reason, most likely the CF Updater, it is now working. Append the session variables to the action page url. Use the same example I told Stuart above. Use a hidden field: <cfinput type="hidden" name="sessionvars" value="#session.urltoken#">
and append that to the url. If you are using the custom tag it would be something like
actionFile='upload.cfm?" + myForm.sessionvars + "'

Regarding your first question about cfmodule, the syntax would be:

<cfset params = structnew()/>
<cfset params["name"] = "myPictureField" />
<cfset params["actionFile"] = '/myRoot/upload.cfm' />

<cfmodule template="/webs/02005/cftags/cfform_fileUpload/fileupload.cfm" attributeCollection="#params#">
<cfmodule template="/webs/02005/cftags/cfform_fileUpload/flashUploadInput.cfm" />
</cfmodule>

The problem is that the custom tag requires a name attribute, but that conflicts with the name attribute of cfmodule, so you need to use attributeCollection.
Jason Weible
92. Jason Weible wrote on October 24, 2005 at 12:26 PM
Hi Laura,

First, thanks for the follow up response.

I tried your suggestion, and was unable to make it work. I suspect maybe there is a version difference between my version of CF and yours. Could you tell me what yours is? The server I am hosted on is running 7,0,1,116466 which is the 6.1 updater - so I don't think there is a newer one out there.

The only other option I can think of is possibly the way my application.cfm is structured is causing the problem.

Here's how I called the tag - it successfully sent the CFTOKEN and CFID values according to Fiddler, but I still get the log in box.


<cf_flashUpload name="productImage" actionFile="uploadImage.cfm?#SESSION.urltoken#&itemID=#URL.itemID#">                  
<cf_flashUploadInput progressBarStyle="#progressBarStyle#" buttonStyle="#buttonStyle#" inputWidth="150" />
</cf_flashUpload>
Jason
93. Jason wrote on October 24, 2005 at 5:05 PM
I'm also getting this, but I'm not sure of the significance since I've never seen an error like this before.

<head><title>JRun Servlet Error</title></head>
<h1>500 Corrupt form data: premature ending</h1>
<body>Corrupt form data: premature ending</body>

Sorry for so many posts. ><
Laura
Jason,
You are not using the accept attribute of cffile, right?
Regarding the updater, I have the same version as you, but I just remembered that I also applied the cffile hotfix that was released shortly after the updater (hf70160996_cffile_upload.jar).
Once you have it working (hopefully you will), transfer the session and itemId vars to a hidden field, otherwise your form will recompile each time one of those change.
Jason
95. Jason wrote on October 24, 2005 at 9:43 PM
Negatory on the accept attribute of cffile.

I'll speak to my server host about the hot fix and see if that helps. :) Thanks for the info!

I'll also get the variables passed via hidden fields, thanks for that tip!
Nathbot
96. Nathbot wrote on October 28, 2005 at 5:08 AM
Hi everyone,

I'm using this great piece in a Fusebox application and it works. I've seen that some people have problem with it, so here how I configured it:

In my case, upload.cfm is in the same folder as the caller page. I am uploading in a folder "images" which is at the site root

actionFile = "upload.cfm"

and in my upload.cfm page:
destination="#expandpath('../images')#"

I hope it will help you guys!

-------

On another hand, I have a small question.
I'd like to update a datagrid field with the image name after having clicked "Choose file" and..well, chosen a file.
I tried to bind a text input to the img_name field, and then apply an "onChange" action to this input, but it doesn't work.
I can't seem to find where I could modify the CFtag code to launch an action after having chosen the file... Any idea?

And thanks again for your great work, which often saves my day.
Nathbot
97. Nathbot wrote on October 28, 2005 at 5:09 AM
Sorry, I realize I forgot to mention that my caller page is in a folder "Admin", also at the site root (hence the "../images" in the ExpandPath)
Nathbot
99. Nathbot wrote on October 28, 2005 at 5:51 AM
Yay!
I never thought of using the &quot;show image after upload&quot; code to do this... I got pretty blind with my eyes glued to my own code. Ouch!
Thanks a lot Todd!
Jason
100. Jason wrote on October 28, 2005 at 10:51 AM
Unfortunetely, it doesn't work for me Nathbot.
I'm glad it work for you! btw, which version of FB you using?
I'm in FB4.1 MVC
Matt
101. Matt wrote on November 10, 2005 at 2:54 AM
change your publishing settings to flash player 8.0 :-) I have just realised how stupid and easy it is :-(
Don
102. Don wrote on November 12, 2005 at 2:55 PM
I was wondering if anyone could help me on this one. I'm trying to add two upload fields in the same action but it wont load. I used two &quot;&lt;cf_flashUploadInput.. &quot; inside &lt;cf_flashUpload, and i tried other avenues but non working, im trying to be able to upload 2 files and add comments in another field, how can I do this?

Thanks guys
Don
103. Don wrote on November 12, 2005 at 3:05 PM
^^^^^^^^^^
Scrach some of that, now I just need help on adding input text fields to the flash uploader for descriptions for that image thats being uploaded...
I read all the posts and found the section for the multiple file uploads, now i need help on this one.
Noel
104. Noel wrote on November 12, 2005 at 3:35 PM
Hi all,

What wysiwyg editor/programs do you use to edit this 'cfflash' stuff?

I am using 'Dreamweaver' and 'Notepad', but they do not really work for layout stuff.
Laura
Don,
You can only send variables through url query string. Otherwise, you can submit the form to get the additional image data.

Noel,
We can't recommend you anything as we code them by hand using Eclipse or CF Studio. But you could try Flex builder and try to translate it to cfform.
Nathbot
106. Nathbot wrote on November 21, 2005 at 1:53 AM
Hi Jason,

I think I've figured out you can make this work on Fusebox (I'm using 4.1 as well).

I'm gonna try to make it simple...

First, check this line in flashUpload.cfm:

<cfparam name="attributes.swf" default="path_to_folder/fileUpload.swf">

the "path_to_folder" thing must be in the fusebox way, i.e. if your swf is in the folder "admin" which is at the root, you just put "admin/fileUpload.swf".

Then, in upload.cfm:
what I hadn't figured out before, is that the path is relative to the previous param. For instance, in my case, I upload files to a folder named "docs" which is also at the site root. So I use this destination path: #expandpath('../docs/')#

I hope this time it helps you, tell me if you still have problems!
Antwain
107. Antwain wrote on November 21, 2005 at 8:02 PM
Help, I'm still getting the HTTP Error number:500. Has anybody else got this error and fixed it?
Lamonte
108. Lamonte wrote on November 22, 2005 at 12:55 PM
Works fine locally, but when I upload the files to a remote server its says that the file has been uploaded but then nothing ever shows up in the specified folder, or any folder for that matter. Can someone help me with this?
Anny
109. Anny wrote on November 23, 2005 at 4:41 AM
Can i upload file with Drag and drop mechanism?
Danny Young
Forgive me for not reading through all of these comments, but is there a way to add another input, say a text field? I have an upload function that requires the user to type in a description, which also gets put into the database.

Thanks,
Danny Young
Robert
This is probably a lower level question, but I have been able to get this working using Firefox on my shared server. However, in IE the file selection box doesn't appear, and on my local dev server when I load the index.cfm page in either FF or IE I just get a blank page. What do I need to do with Flash or CF to fix this? Note, this may also be why I get some kind of OCX (or something) error when I run a flash cfchart from my local/dev server. Thanks.