aboutsummaryrefslogtreecommitdiff
path: root/qc_app/files.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-12-11 10:53:46 +0300
committerFrederick Muriuki Muriithi2023-12-11 10:53:46 +0300
commit2515dfb7100edf5aaeb0f1a1a1be1d034e39904e (patch)
tree257df99eebc2c11e4e230db4aec46f8653dbdf24 /qc_app/files.py
parent49b67d306147ab21f91aaf00831d5b36e28585f6 (diff)
downloadgn-uploader-2515dfb7100edf5aaeb0f1a1a1be1d034e39904e.tar.gz
samples: Fix bugs in code saving samples to db
* Check whether first row in file is for headings * Break infinite loop: check batch has content * Update saving of uploaded files
Diffstat (limited to 'qc_app/files.py')
-rw-r--r--qc_app/files.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/qc_app/files.py b/qc_app/files.py
index 6485b27..0304296 100644
--- a/qc_app/files.py
+++ b/qc_app/files.py
@@ -3,18 +3,16 @@ from pathlib import Path
from typing import Union
from werkzeug.utils import secure_filename
-from flask import (
- request,
- current_app as app)
+from werkzeug.datastructures import FileStorage
-def save_file(key: str, upload_dir: Path) -> Union[Path, bool]:
+def save_file(fileobj: FileStorage, upload_dir: Path) -> Union[Path, bool]:
"""Save the uploaded file and return the path."""
- if not bool(request.files.get(key)):
+ if not bool(fileobj):
return False
- filename = Path(secure_filename(request.files[key].filename))
+ filename = Path(secure_filename(fileobj.filename)) # type: ignore[arg-type]
if not upload_dir.exists():
upload_dir.mkdir()
filepath = Path(upload_dir, filename)
- request.files["samples_file"].save(filepath)
+ fileobj.save(filepath)
return filepath