improved upload logic, thanks Marin

This commit is contained in:
mdipierro
2012-08-03 09:02:38 -05:00
parent 38ceeb82b8
commit 32bfda0b00
2 changed files with 12 additions and 7 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-08-03 09:01:00) dev
Version 2.00.0 (2012-08-03 09:02:35) dev
+11 -6
View File
@@ -1243,14 +1243,19 @@ class SQLFORM(FORM):
else:
fields[fieldname] = ''
self.vars[fieldname] = fields[fieldname]
if not f: continue
if hasattr(f, 'file'):
if not f:
continue
else:
f = os.path.join(current.request.folder,
os.path.normpath(f))
source_file = open(f, 'rb')
original_filename = os.path.split(f)[1]
elif hasattr(f, 'file'):
(source_file, original_filename) = (f.file, f.filename)
elif isinstance(f, (str, unicode)):
f = os.path.join(current.request.folder,
os.path.normpath(f))
source_file = open(f, 'rb')
original_filename = os.path.split(f)[1]
### do not know why this happens, it should not
(source_file, original_filename) = \
(cStringIO.StringIO(f), 'file.txt')
newfilename = field.store(source_file, original_filename,
field.uploadfolder)
# this line is for backward compatibility only