changeset 15:1ee374416987

handle more gracefully when no file is uploaded
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 12 Jul 2011 09:18:29 -0700
parents 916d45d4f921
children 657e8df14187
files uploader/handlers.py
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/uploader/handlers.py
+++ b/uploader/handlers.py
@@ -48,17 +48,20 @@ class Post(Handler):
 
     def write(self, fin, path):
         fout = file(path, 'w')
         fout.write(fin.file.read())
         fout.close()
 
     def __call__(self):
         fin = self.request.POST['file']
-        _path = fin.filename.replace('..', '_')
+        try:
+            _path = fin.filename.replace('..', '_')
+        except AttributeError: # no file uploaded
+            return self.redirect(self.link('/'))
         _path = _path.replace(os.path.sep, '_')
         _path = os.path.join(self.app.directory, _path)
         self.write(fin, _path)
         return self.redirect(self.link('/?uploaded=' + fin.filename))
 
 def path(directory, request):
     if os.sep == '/':
         return os.path.join(directory, request.path_info.strip('/'))