From c6c2f8819fc57f538764f3bccc7580bc6d94e25b Mon Sep 17 00:00:00 2001 From: hernani Date: Thu, 15 Jul 2010 10:47:40 +0000 Subject: [PATCH] Fixes OSQA-142, spaces in uploaded image names = FAIL. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@530 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/views/writers.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/forum/views/writers.py b/forum/views/writers.py index c9b005b..74708d6 100644 --- a/forum/views/writers.py +++ b/forum/views/writers.py @@ -37,13 +37,16 @@ def upload(request):#ajax upload file to a question or answer raise UploadPermissionNotAuthorized() # check file type - file_name_suffix = os.path.splitext(f.name)[1].lower() + try: + file_name_suffix = os.path.splitext(f.name)[1].lower() + except KeyError: + raise FileTypeNotAllow() if not file_name_suffix in ('.jpg', '.jpeg', '.gif', '.png', '.bmp', '.tiff', '.ico'): raise FileTypeNotAllow() storage = FileSystemStorage(str(settings.UPFILES_FOLDER), str(settings.UPFILES_ALIAS)) - new_file_name = storage.save(f.name, f) + new_file_name = storage.save("_".join(f.name.split()), f) # check file size # byte size = storage.size(new_file_name) -- 2.39.5