Skip to content

Commit

Permalink
FIX Allowing upload of files without loading the whole file into memory
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsMichelsen committed Feb 13, 2014
1 parent 0aa4340 commit 9046981
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .werks/668
@@ -0,0 +1,8 @@
Title: Allowing upload of files without loading the whole file into memory
Level: 1
Component: multisite
Version: 1.2.5i1
Date: 1392304629
Class: fix


1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -217,6 +217,7 @@
* 0273 FIX: Fixed exceptions when modifying / cloning views...
* 0274 FIX: Fixed exception when view title or description was missing
* 0278 FIX: Fixed bookmark icon images for non-english user languages...
* 0668 FIX: Allowing upload of files without loading the whole file into memory

WATO:
* 0308 Multisite can now set rotation view permissions for NagVis...
Expand Down
15 changes: 9 additions & 6 deletions web/htdocs/htmllib.py
Expand Up @@ -1251,14 +1251,13 @@ def set_tree_states(self, tree, val):
self.load_tree_states()
self.treestates[tree] = val

def parse_field_storage(self, fields):
def parse_field_storage(self, fields, handle_uploads_as_file_obj = False):
self.vars = {}
self.listvars = {} # for variables with more than one occurrance
self.uploads = {}

for field in fields.list:
varname = field.name
value = field.value

# To prevent variours injections, we only allow a defined set
# of characters to be used in variables
Expand All @@ -1267,19 +1266,23 @@ def parse_field_storage(self, fields):

# put uploaded file infos into separate storage
if field.filename is not None:
self.uploads[varname] = (field.filename, field.type, field.value)
if handle_uploads_as_file_obj:
value = field.file
else:
value = field.value
self.uploads[varname] = (field.filename, field.type, value)

else: # normal variable
# Multiple occurrance of a variable? Store in extra list dict
if varname in self.vars:
if varname in self.listvars:
self.listvars[varname].append(value)
self.listvars[varname].append(field.value)
else:
self.listvars[varname] = [ self.vars[varname], value ]
self.listvars[varname] = [ self.vars[varname], field.value ]
# In the single-value-store the last occurrance of a variable
# has precedence. That makes appending variables to the current
# URL simpler.
self.vars[varname] = value
self.vars[varname] = field.value

def uploaded_file(self, varname, default = None):
return self.uploads.get(varname, default)
Expand Down

0 comments on commit 9046981

Please sign in to comment.