Skip to content
Snippets Groups Projects
Commit 28dec163 authored by Renzo Frigato's avatar Renzo Frigato
Browse files

fix uploads of small files

cgi.FieldStorage by default doesn't use make_file.
Only if the file is bigger than 1000 bytes the method is called.
Overriding the private method __write allows to always call the method
independently of file size.

closes #88
parent e9f811e2
No related branches found
No related tags found
No related merge requests found
......@@ -34,9 +34,20 @@ def getHashingFieldStorage(upload_dir, hash_alg):
class HashingFieldStorage(cgi.FieldStorage):
bufsize = 2**20
def make_file(self, binary=None):
if not self.filename:
return self.file
self.open_file = HashingFile(os.path.join(upload_dir, os.path.basename(self.filename)), hash_alg)
return self.open_file
# override private method __write of superclass FieldStorage
# _FieldStorage__file is the private variable __file of the same class
def _FieldStorage__write(self, line):
if self._FieldStorage__file is not None:
self.file = self.make_file('')
self.file.write(self._FieldStorage__file.getvalue())
self._FieldStorage__file = None
self.file.write(line)
def get_hash(self):
return self.open_file.get_hash()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment