From 7bc68b92c6aa02857408a3c38f74737aa7a99602 Mon Sep 17 00:00:00 2001 From: Akshay Karle <1443108+akshaykarle@users.noreply.github.com> Date: Thu, 30 May 2024 16:06:55 +0100 Subject: [PATCH] create file upload directory to store files temporarily for analyzer --- .gitignore | 3 ++- src/app.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 048e7df..b7c10b4 100644 --- a/.gitignore +++ b/.gitignore @@ -159,4 +159,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ -.direnv/ \ No newline at end of file +.direnv/ +file_uploads/ \ No newline at end of file diff --git a/src/app.py b/src/app.py index 48e840f..c94c97d 100644 --- a/src/app.py +++ b/src/app.py @@ -11,6 +11,7 @@ DEFAULT_PORT = "3000" NLP_ENGINE = "flair/ner-english-large" +UPLOAD_DIR = "./file_uploads" class Server: """HTTP Server for calling Presidio Analyzer.""" @@ -23,6 +24,8 @@ def __init__(self): nlp_engine = FlairNLPEngine(NLP_ENGINE) self.engine = CSVAnalyzerEngine(nlp_engine) self.logger.info("Started analyzer engine") + if not os.path.exists(UPLOAD_DIR): + os.makedirs(UPLOAD_DIR) @self.app.route("/health") def health() -> str: @@ -37,7 +40,7 @@ def analyze() -> Tuple[str, int]: if file.filename == '': return jsonify({'error': 'No selected file'}), 400 - filepath = f'uploads/{uuid.uuid4()}' + filepath = f'{UPLOAD_DIR}/{uuid.uuid4()}' file.save(filepath) self.logger.info(f"Successfully saved file: {filepath}")