Hey. How can I save the file when using the 'File' form?

code.py


   1. import web, shutil
      2. from web import form
      3.  
      4. urls = ('/', 'Index')
      5.  
      6. app = web.application(urls, globals())
      7. render = web.template.render()
      8.  
      9. fileForm = form.Form(form.File('myfile'))
      10.  
      11. class Index(object):
      12.         def GET(self):
      13.                 f = fileForm()
      14.                 return render.index(f)
      15.         def POST(self):
      16.                 f = fileForm()
      17.                 fi = f['myfile']
      18.                 mydir = 'uploads/'
      19.                 shutil.copy(fi, mydir)
      20.                 
      21. if __name__ == "__main__":
      22.         app.run()
      

templates/index.html


   1. $def with (f)
      2. <!DOCTYPE html>
      3. <html>
      4.  
      5. <head> 
      6.  
      7. <title>My cool file uploader</title>
      8.  
      9. </head>
      10.  
      11. <body>
      12. <form name="main" method="post" enctype="multipart/form-data" 
      action="">
      13. $:f.render()
      14. <input type="submit">
      15. </form>
      16. </body>
      17.  
      18. </html>
      


This gives me: " <type 'exceptions.TypeError'> at /coercing to Unicode: 
need string or buffer, File found "


Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to webpy+unsubscr...@googlegroups.com.
To post to this group, send email to webpy@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to