Skip to content

Commit

Permalink
TLDR-517 fix attachments handler
Browse files Browse the repository at this point in the history
  • Loading branch information
NastyBoget committed Nov 23, 2023
1 parent d3c958b commit 3f7b51f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions dedoc/attachments_handler/attachments_handler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import copy
import logging
import os
import shutil
import tempfile
import time
from typing import List

Expand Down Expand Up @@ -64,12 +62,12 @@ def handle_attachments(self, document_parser: "DedocManager", document: Unstruct

try:
if attachment.need_content_analysis:
with tempfile.TemporaryDirectory() as tmpdir:
attachment_path = os.path.join(tmpdir, attachment.get_original_filename())
shutil.copy(attachment.get_filename_in_path(), attachment_path)
parsed_file = document_parser.parse(attachment_path, parameters=parameters_copy)
parsed_file = document_parser.parse(attachment.get_filename_in_path(), parameters=parameters_copy)
else:
parsed_file = self.__get_empty_document(document_parser=document_parser, attachment=attachment, parameters=parameters_copy)

parsed_file.metadata.file_name = attachment.original_name # initial name of the attachment
parsed_file.metadata.temporary_file_name = os.path.split(attachment.get_filename_in_path())[-1] # actual name in the file system
except DedocError:
# return empty ParsedDocument with Meta information
parsed_file = self.__get_empty_document(document_parser=document_parser, attachment=attachment, parameters=parameters_copy)
Expand Down

0 comments on commit 3f7b51f

Please sign in to comment.