diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-07-29 16:17:43 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-07-29 16:17:43 +0200 |
commit | 5aa1666cbe5482af7b79d0ee635423500b2fdc88 (patch) | |
tree | 033127f788e84a4dd35e3f38dbe0ae90769938bf | |
parent | 8b6fd105f67898a516b5e21cad566950e5dac99d (diff) |
Write file uploads to temp file while hashing.
This avoids loading the file into memory, which is bad for huge files.
-rwxr-xr-x | fbin.py | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -159,15 +159,15 @@ class Application(object): filename = form.getvalue('filename') temp = tempfile.NamedTemporaryFile(mode = 'wb', prefix = 'fbin', delete = True) - temp.write(form.getvalue('file')) - temp.flush() + f = form['file'].file m = hashlib.md5() - with open(temp.name) as f: + s = f.read(128) + while len(s): + m.update(s) + temp.write(s) s = f.read(128) - while len(s): - m.update(s) - s = f.read(128) + temp.flush() file_hash = m.hexdigest() f = self.get_file_by_file_hash(file_hash) |