Ask An Addict: CFMU upload and insert

Tags: CFMU
Word Count: 407

I got this question from a user so I thought I would share it with everyone.

Anyway, I downloaded your CFMU tag and think it's amazing. I'd really like to be able to make use of it but would need to know the names of the files it uploads for storing in a database etc. I've been scratching my head over the OnComplete Advanced example you gave in the documentation but my JavaScript is useless and my ColdFusion knowledge just isn't good enough to work out a different way!

First off thanks for the kind words! Ok so the on complete method is really there to be used as a callback method. This will allow you to call a javascript method after the files have been uploaded. While I guess you could use this to make Ajax calls to your backend and write to a database I think there is a better way to go about this. If you download the latest zip I have added a new example.

Remember that all the uploader tag does is push the file to a specific URL. This is the example code from my the demo upload and insert. As you can see there is a URL attribute. This is the URL that gets called everytime we upload a file.

So we know its going to call a component name ImageHandler.cfc and a method named upload. Basically Flash passes the filename through a form variable to our remote method. The same way that we use the form.filename field to upload the file, we can use it to insert the name into a database. This example is very basic but as you can see we are uploading the image and adding it to our database. You could even take this a step further and wrap it in a transaction so that if either fail you can just rollback.

Comments

#1 Posted By: Brian Posted On: 7/15/09 3:01 PM
Dan, am I understanding this tag correctly that, at least in this example, you're accepting the path from the *client* for where to upload the file? I don't know if this is part of the distribution or not, but you might consider writing the upload handler based on Pete Freitag's good article on secure file uploads:

http://www.petefreitag.com/item/701.cfm

Project looks cool; planning to give the upload widget a shot. I know nothing about Flex so I appreciate you sharing a nice UI like this.
#2 Posted By: Dan Vega Posted On: 7/15/09 3:48 PM |
Author Comment
I will take a look at it. Please let me know what you think of the uploader.
#3 Posted By: Lee Posted On: 12/1/09 7:09 AM
Dan, I can't seem to get the upload and insert example to work. The files get successfully uploaded but I get an I/O error and the 'insert' part just doesn't work. All I'm doing is inserting the filename in the same way as your example. I've tried replacing the query with a CFSET which assigns the filename to a SESSION variable but even this doesn't seem to work. What could be going wrong?

Apart from that, great tag!


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.