From c7a728ce84111b9a73edf84491afe349a3d0761c Mon Sep 17 00:00:00 2001 From: Mia Herkt Date: Thu, 11 Aug 2022 05:49:46 +0200 Subject: [PATCH] Fix non-seekable file handles Closes #59 --- fhost.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fhost.py b/fhost.py index 2703810..9c2b94b 100755 --- a/fhost.py +++ b/fhost.py @@ -140,7 +140,7 @@ class File(db.Model): return url_for("get", path=n, _external=True) + "\n" def store(file_, addr): - data = file_.stream.read() + data = file_.read() digest = sha256(data).hexdigest() def get_mime(): @@ -192,8 +192,8 @@ class File(db.Model): p = storage / digest if not p.is_file(): - file_.stream.seek(0) - file_.save(p) + with open(p, "wb") as of: + of.write(data) else: p.touch() @@ -287,7 +287,7 @@ def store_url(url, addr): def urlfile(**kwargs): return type('',(),kwargs)() - f = urlfile(stream=r.raw, content_type=r.headers["content-type"], filename="") + f = urlfile(read=r.raw.read, content_type=r.headers["content-type"], filename="") return store_file(f, addr) else: