On Thursday 03 July 2008 16:02:40 zaf wrote: > Hello all, > I have a form in which I have at least one file chooser input. It's > like a file attachment system basically, I can add as many file > chooser inputs as I have files to attach. > Those inputs all have the same html name attribute (say 'file'). > > <input type="file" name="file"></input> > > So when the form is posted and the data arrives in my controller > method I would just have to iterate over that particlar name. > Basically : > > def upload(self, **args): > for item in args['files']: > do something on this file... > > There's just one problem : this works fine if I have more than one > field with the name 'file'. however if I only have one field, the > method will not receive a list but an object of the type FieldStorage > and thus I can't iterate over it. > > Is there any way I can force this to always be in a list ? It would be > a great hepl and I don't really want to have to use hack such has > isinstance or other... (I will if I have to though)
You possibly can do that using the ForEach-validator with convert_to_list=True. Works for other values, not sure about files though - you might want to add a Identity (as in identity-function, not as in user-identity) validator to make it work. Diez --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

