[TurboGears] Re: File upload - how to get filename?
On 10/27/06, Robin Haswell [EMAIL PROTECTED] wrote: Hey I need to get the filename of an uploaded file from CherryPy. Just wanted to know if you read this 2, they are hidden :) if you did please ignore http://trac.turbogears.org/turbogears/wiki/FileUploadTutorial http://www.cherrypy.org/browser/trunk/cherrypy/tutorial/tut09_files.py?rev=1219 as Bob pointed out there is no need to know the name. Cheers -Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups TurboGears group. To post to this group, send email to turbogears@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears -~--~~~~--~~--~--~---
[TurboGears] Re: File upload - how to get filename?
Bob Ippolito wrote: def upload_form(self, formfile): import tempfile import shutil from pysqlite2 import dbapi2 as sqlite newfile = tempfile.NamedTemporaryFile() shutil.copyfileobj(formfile.file, newfile) newfile.flush() con = sqlite.connect(newfile.name) Looks good to me boss, I'll give it a test when I find out how to relate my Posts! Cheers -Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups TurboGears group. To post to this group, send email to turbogears@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears -~--~~~~--~~--~--~---
[TurboGears] Re: File upload - how to get filename?
On 10/27/06, Robin Haswell [EMAIL PROTECTED] wrote: I need to get the filename of an uploaded file from CherryPy. I can't write this to a different (known) file because I don't seem to be able to get a filename out of os.tmpfile(). I need the filename to pass to pysqlite2 - I'm uploading sqlite databases which need to be read. If anyone can let me know how to get the filename of an uploaded file (I assume it's some temp file), or any other solution to my problem, it would be very much appreciated. I don't really want my own method of generating temp filenames - I'd prefer to leave symlink attack prevention to the professionals. The temporary files created during file uploads (tempfile.TemporaryFile instances) do not have names on all platforms, you will have to create a new file and copy the data into it. You can get a named temporary file out of the tempfile module (tempfile.NamedTemporaryFile). Something like this probably would work:: def upload_form(self, formfile): import tempfile import shutil from pysqlite2 import dbapi2 as sqlite newfile = tempfile.NamedTemporaryFile() shutil.copyfileobj(formfile.file, newfile) newfile.flush() con = sqlite.connect(newfile.name) -bob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups TurboGears group. To post to this group, send email to turbogears@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears -~--~~~~--~~--~--~---