Skip to content

Commit

Permalink
Merge pull request #100 from bento-platform/fix/temp-file-writing
Browse files Browse the repository at this point in the history
fix: write temp file uploads (during upload) to ingest tmp dir
  • Loading branch information
davidlougheed authored Apr 12, 2024
2 parents 74a8ee1 + e362895 commit 2802115
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions chord_drs/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
from .constants import SERVICE_NAME
from .db import db
from .metrics import metrics
from .request import DrsRequest
from .routes import drs_service


MIGRATION_DIR = os.path.join(APP_DIR, "migrations")

application = Flask(__name__)
application.config.from_object(Config)
application.request_class = DrsRequest

# Set up CORS
CORS(
Expand Down
18 changes: 18 additions & 0 deletions chord_drs/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask import Request, current_app
from tempfile import SpooledTemporaryFile
from typing import IO, Optional

__all__ = ["DrsRequest"]

MAX_IN_MEMORY_SIZE = 1024 * 1024 # 1 MB


class DrsRequest(Request):
def _get_file_stream(
self,
total_content_length: Optional[int],
content_type: Optional[str],
filename: Optional[str] = None,
content_length: Optional[int] = None,
) -> IO[bytes]:
return SpooledTemporaryFile(max_size=MAX_IN_MEMORY_SIZE, dir=current_app.config["DRS_INGEST_TMP_DIR"])
1 change: 1 addition & 0 deletions chord_drs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ def object_ingest():
filename: str | None = None # no override, use path filename if path is specified instead of a file upload
if file is not None:
logger.debug(f"ingest - received file object: {file}")
logger.debug(f"ingest - writing to temporary path: {t_obj_path}")
file.save(t_obj_path)
obj_path = t_obj_path
filename = file.filename # still may be none, in which case the temporary filename will be used
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "chord-drs"
version = "0.16.0"
version = "0.16.1"
description = "An implementation of a data repository system (as per GA4GH's specs) for the Bento platform."
authors = ["David Lougheed <[email protected]>"]
license = "LGPL-3.0"
Expand Down

0 comments on commit 2802115

Please sign in to comment.