diff --git a/app/routers/event_file.py b/app/routers/event_file.py index 17c7ac7..58f1c55 100644 --- a/app/routers/event_file.py +++ b/app/routers/event_file.py @@ -163,13 +163,20 @@ async def download_event_file( hash_sha256 = event_file_obj.hosted_file.hash_sha256 hash_filename = hash_sha256+'.file' - full_subdirectory_path = os.path.join(hosted_files_path, subdir_path) + if subdir_path: + full_subdirectory_path = os.path.join(hosted_files_path, subdir_path) + else: + full_subdirectory_path = hosted_files_path log.debug(full_subdirectory_path) pathlib.Path(full_subdirectory_path).mkdir(parents=True, exist_ok=True) file_path_w_subdir = os.path.join(full_subdirectory_path, hash_filename) log.info(f'Full file path with subdirectory: {file_path_w_subdir}') - return FileResponse(file_path_w_subdir, filename=filename) + if os.path.exists(file_path_w_subdir): + return FileResponse(file_path_w_subdir, filename=filename) + else: + log.error(f'The hosted file was not found on the server. Hash: {hash_sha256}') + return mk_resp(data=False, status_code=400, response=commons.response, status_message='The hosted file was not found on the server.') # Bad Request # ### END ### API Hosted File ### download_tmp() ###