Real World Flex/ColdFusion: Part 11

Word Count: 357

This will be the last post in this series. While I will continue to add features to this project and share the details with you, I wanted to find a clear line where I could close this series. The last feature is probably the most important. What good is a file manager if you can't upload new files. This post will cover the upload component.

First we are going to create a new file components/RocketUploader. The component we are creating is going to be based on a Title Window because we are going to launch the uploader as a popup from our application. The layout of the component is pretty simple. I know we talked about layouts at the beginning of this series and I am doing the exact opposite of what I preached but I just like the look and feel of the panel component here. In the panel we have some buttons, a data grid to display the files and progress bar to show file upload progress.

To upload a file you will click on the browse button, select some files and click the upload button. To present the user with a browse dialog box we will work with the FileReference class. When the user selects a file or files the onSelectFile method is called. For each file that was selected we will loop through and add it to our _files array.

When the user clicks the upload button we are going to call the on upload method. For each file in the list we are going to push the file to our File Manager component method upload. The important thing to notice here is that one of the events we can listen for is the complete event. In our complete event handler we are going to remove the item from the data grid and dispatch a new custom event to our application. The custom event basically tells our application that we need to update the file listing and we will push the path along with the event.

Back in our main application we need to set a click handler for the upload button. In the openUploader method we are creating an instance of our RocketUploader and adding it to the screen using the popup manager. Another cool little lesson here is figuring out what to set the width and height of our uploader. Usually you can set a percentage width but here what don't know what width is so this won't work. What we want to do is figure out what the stage size is and take about 60% of that.

With that I think we are going to end this series. You can check out a screen shot below of the upload component in action. I will posting more updates to the application in the near future but for now you can grab the code from svn over at http://rocketfm.riaforge.org. Please feel free to contact me with any questions or problems that you run into.

Comments

#1 Posted By: Gareth Arch Posted On: 1/11/09 10:45 PM
Nice finish to the series. It's been interesting following along. I'm looking forward to what the future holds for this project. Maybe a nice AIR version of it (as it has access to the local file system without the need for the CF files). I'll have to download the source and tinker with it a little.

One minor text change that I noticed in this entry..."What good is a file manager if you can upload new files." That should be "can't" I think :) (I don't usually comment on textual changes as I know that is kind of annoying, but I figured this one might confuse people if it wasn't changed)
#2 Posted By: Dan Vega Posted On: 1/11/09 10:49 PM |
Author Comment
I am glad your enjoyed the series. As I said, there are going to be updates to the project and AIR application is not a bad idea! Thanks for the text change, I updated the post.
#3 Posted By: Steven Erat Posted On: 1/12/09 5:33 PM
Dan,

Fun and educational tutorial. Thank you for your effort towards creating it.

Earlier you mentioned that you put your Flex project under your ColdFusion webroot in order to make the rocketfm CFCs accessible over localhost. Since I tend to put my svn projects under C:\svn on Windows, to make rocketfm available through ColdFusion I added a rocketfm virtual mapping in jrun-web.xml just above the existing mapping for WEB-INF like this (angle brackets replaced with square ones here:)

--------------
[virtual-mapping]
[resource-path]/rocketfm[/resource-path]
[system-path]C:/svn/rocketfm/trunk[/system-path]
[/virtual-mapping]

[virtual-mapping]
[resource-path]/rocketfm/*[/resource-path]
[system-path]C:/svn/rocketfm/trunk/[/system-path]
[/virtual-mapping]

[virtual-mapping]
[resource-path]/WEB-INF[/resource-path]
[system-path]C:/ColdFusion8/wwwroot/WEB-INF[/system-path]
[/virtual-mapping]
-----------------

Also, since I'm using CF Server Config ("Standalone"), I changed the Flex project services-config path accordingly.

I tried this with CF7 and encountered a CF compiler error in the Flex debug output in the cfstart console regarding the use CF8 tags cfzip and cfzipparam. Even though you split the zip function into two versions, the very existence of the tags in the component is problematic on CF7. You may have to split it into version-specific CFCs rather than version-specific functions.

Again, love the series. I'm finding it very useful.
#4 Posted By: Steven Erat Posted On: 1/12/09 7:17 PM
Interesting...

When I ran ColdFusion from cfstart, the server runs as my user account, not System. Under this condition the rocketfm application would hang, and the cf console showed a flex error for Variable CHILDREN not defined. I tracked it down to a permissions problem. If the user account does not have permission to read directory contents, then the FileManager.cfc method getDirectories will fail after the lines:

// loop this directory to see if it has any children
children = files[i].listFiles();

Here children becomes null and isDefined("children") evaluates to NO after that line. I noticed there is a "trap for null" block after this, but is empty. I believe that if you recreate the children variable in the trap for null block then the problem would not occur.

Additionally, you might want to set another file property regarding permissions such that directories hit the null trap are marked with a red icon for example.

Just a few thoughts...
#5 Posted By: Dan Vega Posted On: 1/12/09 7:54 PM |
Author Comment
It's funny you mentioned the permission issue because we just ran into the same issue moving it to another server today. First we had the everyone group allowed to access it and it worked fine then we targeted to that machine and I was still getting the errors above. Finally we figured it was the local account that needed access to it. Thanks for the tip!

As far as the CF7 issue I totally forgot that when you create a instance of it there would be problems. I will split that out later tonight.
#6 Posted By: George Smith Posted On: 12/17/09 1:40 PM
Maybe Im a dumby but... I did not see anywhere in the series about editing the .html file. I can see that that is where the root directory is set up. I must be dumb though because even after editing the flash vars I still just get an empty panel. Nor do I see any java files. Nor do I see a data folder that is refered to in the .html file. I have been searching the web for months to find a simple Tree displaying a directory. Your sample has the closest thing but I never actually see it work. By the way links to each next article would be a good thing. Thanks
#7 Posted By: Dan Vega Posted On: 12/17/09 3:21 PM
George - This is written in Flex. Flex has a tree view control that you can customize. The actually data is being pulled on the backend using ColdFusion.

http://livedocs.adobe.com/flex/3/html/help.html?co...
#8 Posted By: George Smith Posted On: 12/28/09 12:38 PM
Got it. Everything works perfectly except. When I upload a file Iget an error: Erroe #2038 not sure what this means,I read... file to big (not the problem) server busy (not the problem). I can create folders and delete folders. Stumped but really great tutorial all the same. Thanks


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.