Ticket #424 (closed enhancement: completed)
Add "file" input tag to form tag library
| Reported by: | mattwoodward | Owned by: | mattwoodward |
|---|---|---|---|
| Priority: | blocker | Milestone: | Mach-II 1.8.0 beta |
| Component: | framework - custom tags | Version: | 1.8.0 - Framework |
| Keywords: | Cc: | kurtwiersma, mattwoodward, brianfitzgerald, adrianscott, mikerogers | |
| Blocking: | Blocked By: |
Description
Since we added button to the form tag library the only input type missing at this point is file. File uploads have always been a bit messy in Mach-II because what exists in the Mach-II event object when you do a file upload is the file data itself as opposed to a simple string, which means people run into problems when using event.getArg("fileFieldName") in their CFFILE tags.
We wrote an FAQ on this here: http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/FAQUploadingFile
Peter and I discussed this on IM and we came up with the idea of having the file form field tack something unique on the end to indicate it's a file, which makes things a bit easier in the listener that handles the form post. So in your form you'd have something like:
<form:form actionEvent="processFileUpload"> <form:file name="photo" value="Browse" /> <form:button name="button" value="Upload Photo" /> </form:form>
(Note that bind/path syntax will work for the file input as well.)
If you use the form:file tag in your form, Mach-II will add the appropriate enctype to the form tag for you since that's a common thing to forget.
As for the file field itself, this will potentially render something along these lines for the HTML:
<input type="file" name="photo_-_file_-_" value="Browse" />
Note the "_-_file_-_" at the end of the input name. We haven't settled on exactly what that will be, but what we're looking for is some way that will indicate this is a file input, and doing so in such a way that the potential to conflict with something you'd actually use for an input name is minimal.
This leads to the listener. Peter and I talked through several ideas, from leaving the CFFILE bits in the listener method up to the developer to implement, to totally automating things, and I think where we landed was somewhere in the middle, namely that we'd add a new method to the framework to handle file uploads more simply. Of course this would ultimately be a wrapper for CFFILE ACTION="UPLOAD", but would integrate better with Mach-II (certainly much better than what you have to do now!).
Potential syntax:
<cfset uploadResults = uploadFile(arguments.event.getArg("photo"),
"/dest/directory/here") />
Without providing anything else we'd default to: 1. Using the original file name as the name of the file stored on the server 2. Using a nameconflict setting of "makeunique" 3. Note the arguments.event.getArg("photo") bit--we'd tack the _-_file_-_ stuff on the end when grabbing things so you're using the name of the field you specify before it gets modified to indicate it's a file input.
I'd have to think about what else we could intelligently default, but of course you could pass additional parameters as well:
<cfset uploadResults = uploadFile(arguments.event.getArg("photo"),
"/dest/directory/here", "newFileName.jpg", "overwrite")) />
Lastly, the uploadResults would of course contain the typical stuff you're used to having access to after a CFFILE upload. Again, it's a wrapper for CFFILE under the hood but this should make things a bit more slick to use and will certainly integrate with Mach-II much better.
