Fix non-seekable file handles

Closes #59
This commit is contained in:
Mia Herkt 2022-08-11 05:49:46 +02:00
parent 5216e9ebaf
commit c7a728ce84
No known key found for this signature in database
GPG key ID: 72E154B8622EC191

View file

@ -140,7 +140,7 @@ class File(db.Model):
return url_for("get", path=n, _external=True) + "\n" return url_for("get", path=n, _external=True) + "\n"
def store(file_, addr): def store(file_, addr):
data = file_.stream.read() data = file_.read()
digest = sha256(data).hexdigest() digest = sha256(data).hexdigest()
def get_mime(): def get_mime():
@ -192,8 +192,8 @@ class File(db.Model):
p = storage / digest p = storage / digest
if not p.is_file(): if not p.is_file():
file_.stream.seek(0) with open(p, "wb") as of:
file_.save(p) of.write(data)
else: else:
p.touch() p.touch()
@ -287,7 +287,7 @@ def store_url(url, addr):
def urlfile(**kwargs): def urlfile(**kwargs):
return type('',(),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) return store_file(f, addr)
else: else: