I ran into a little problem with the filename parameter in FileFields. I needed to copy the file to a workdir and run an external program with that copied file.
>From Firefox and Safari, everything worked using the example code, but for IE, an extra check for a reverse slash (not a fwd slash) is needed. I pasted the code, along with the expanding form using it: http://paste.turbogears.org/paste/21985 (see copyYangFile) Andy On Dec 27, 11:55 am, "Jorge Vargas" <[email protected]> wrote: > On Fri, Dec 26, 2008 at 2:26 PM, Chen Houwu <[email protected]> wrote: > > > ----------------------------------- > > sample file upload > > ----------------------------------- > > # controller.py > > > @turbogears.expose() > > def upload(self, upload_file, pagename, **keywords): > > try: > > p = Page.byPagename(pagename) > > except SQLObjectNotFound: > > turbogears.flash("Must save page first") > > turbogears.redirect("/%s" % pagename) > > data = upload_file.file.read() > > target_file_name = os.path.join(os.getcwd(), UPLOAD_DIR, > > upload_file.filename) > > try: > > u = UploadedFile.byFilename(upload_file.filename) > > turbogears.flash( > > "File already uploaded: %s is already at %s" % \ > > (upload_file.filename, target_file_name)) > > except SQLObjectNotFound: > > # open file in binary mode for writing > > f = open(target_file_name, 'wb') > > f.write(data) > > f.close() > > turbogears.flash( > > "File uploaded successfully: %s saved as: %s" \ > > % (upload_file.filename, target_file_name)) > > u = UploadedFile(filename=upload_file.filename, > > abspath=target_file_name, size=0) > > > Page.byPagename(pagename).addUploadedFile(u) > > turbogears.redirect("/%s" % pagename) > > Thanks seems to do the trick, And I agree we should have a "file > upload tutorial" somewhere on the site. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

