diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 47dba9412..fa8f8fcfe 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -519,7 +519,11 @@ class Consumer(LoggingMixin): document.filename = generate_unique_filename(document) create_source_path_directory(document.source_path) - self._write(document.storage_type, self.path, document.source_path) + self._write( + document.storage_type, + self.original_path, + document.source_path, + ) self._write( document.storage_type, @@ -711,21 +715,20 @@ class Consumer(LoggingMixin): storage_type = Document.STORAGE_TYPE_UNENCRYPTED - with open(self.path, "rb") as f: - document = Document.objects.create( - title=( - self._parse_title_placeholders(self.override_title) - if self.override_title is not None - else file_info.title - )[:127], - content=text, - mime_type=mime_type, - checksum=hashlib.md5(f.read()).hexdigest(), - created=create_date, - modified=create_date, - storage_type=storage_type, - original_filename=self.filename, - ) + document = Document.objects.create( + title=( + self._parse_title_placeholders(self.override_title) + if self.override_title is not None + else file_info.title + )[:127], + content=text, + mime_type=mime_type, + checksum=hashlib.md5(self.original_path.read_bytes()).hexdigest(), + created=create_date, + modified=create_date, + storage_type=storage_type, + original_filename=self.filename, + ) self.apply_overrides(document) diff --git a/src/documents/parsers.py b/src/documents/parsers.py index 16094810e..aa2645e07 100644 --- a/src/documents/parsers.py +++ b/src/documents/parsers.py @@ -105,7 +105,7 @@ def get_supported_file_extensions() -> set[str]: return extensions -def get_parser_class_for_mime_type(mime_type: str) -> Optional["DocumentParser"]: +def get_parser_class_for_mime_type(mime_type: str) -> Optional[type["DocumentParser"]]: """ Returns the best parser (by weight) for the given mimetype or None if no parser exists