aboutsummaryrefslogtreecommitdiff
path: root/qc_app/files.py
diff options
context:
space:
mode:
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