Ask a Jedi: Flash, ColdFusion and FIle Uploads
Asa asks an interesting question. I wasn't going to answer as Flash isn't my area really, but I had an idea and I figured I'd suggest it. Please feel free to correct me if this is dumb. Anyway, here is the question:
I'm trying to make a file unloader using Flash & ColdFusion. I have a flash file embedded on a page that let's the user select a file, which is then posted to a ColdFusion page for upload. The problem is that the Flash player doesn't post cookies on file uploads, so the ColdFusion page that's getting posted to is under a new session. Is there a way to append the cfid to the url and have ColdFusion use that session instead of making a new one?
So I was a bit surprised by this. I can't imagine why Flash would not do a 'normal' request and pass along the cookies. That being said - I think I know a way to do this. When you generate your HTML code to embed the Flash SWF, you can pass along the session.urltoken value via flash vars. The Flash app could read this and use it when it does its POST.
Right?
Any Flash users out there want to chime in? (I'm sure I must have at least one Flash guy reading the blog. He probably sits next to the one Photoshop guy reading my blog. ;)
Comments
My file was site was protected via CFLOGIN, so I did this on the onRequestStart
<!--- Upload with Safari or Firefox? BUG --->
<cfif CGI.SCRIPT_NAME CONTAINS "admin/galerias/fotos/upload.cfm">
Then I skip the validation.
a href="foo.cfm?#session.urltoken#"
This will append everything CF needs. So if you pass the value to Flash, and Flash does a post to
foo.cfm?INSERT THE VAR HERE IN ACTION SCRIPT
Then it should work just fine. You don't have to make CF work with it - it should "just work".
@Raul: Wow, I got to say though - I think thats a bad idea. It would let anyone upload files.
Everyone can easily hit view source and see the var passed in to the swf via flashVars
Passing #session.urltoken# to the flash file and then appending it to the upload URL works great!
Im curious how you got that to work, its not working for me doing. Did you added the token to the upload method of actionscript or did you sent the token through the data property in the URLRequest class?
I swear that's how I think i did it! I think. ;)
**all my advice comes without warranty and is given with only vague recollections of what once worked.
Would it be possible to use the onRequestEnd method in the application CFC, to add a user's Session ID to the database table?
I envision doing a look-up of the last ID in the DB onRequestEnd.
Thoughts?
I passed the upload path to the SWF as a variable:
file.swf?path=#URLEncodedFormat('UploadImage.cfm?#session.urltoken#')#
you need the URLEncodedFormat around it because session.urltoken is actually 2 url variables.


Here are some more blogs talking about the issue
http://www.visible-form.com/blog/flash-file-upload...
http://robrosenbaum.com/flash/using-flash-upload-w...