diff --git a/apps/converter/backends/python/base.py b/apps/converter/backends/python/base.py index 3e0f8cd84f..a57e1f0d2a 100644 --- a/apps/converter/backends/python/base.py +++ b/apps/converter/backends/python/base.py @@ -25,7 +25,7 @@ class ConverterClass(ConverterBase): def get_page_count(self, input_filepath): page_count = 1 - mimetype, encoding = get_mimetype(input_filepath) + mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath) if mimetype == 'application/pdf': # If file is a PDF open it with slate to determine the page # count @@ -50,7 +50,7 @@ class ConverterClass(ConverterBase): def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT): tmpfile = None - mimetype, encoding = get_mimetype(input_filepath) + mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath) if mimetype == 'application/pdf' and USE_GHOSTSCRIPT: # If file is a PDF open it with ghostscript and convert it to # TIFF diff --git a/apps/documents/models.py b/apps/documents/models.py index 1d4b67881f..efdd6a6841 100644 --- a/apps/documents/models.py +++ b/apps/documents/models.py @@ -17,7 +17,7 @@ from converter.api import get_page_count from converter.api import get_available_transformations_choices from converter.api import convert from converter.exceptions import UnknownFileFormat, UnkownConvertError -from mimetype.api import get_document_mimetype, get_icon_file_path, \ +from mimetype.api import get_mimetype, get_icon_file_path, \ get_error_icon_file_path from documents.conf.settings import CHECKSUM_FUNCTION @@ -135,7 +135,7 @@ class Document(models.Model): """ if self.exists(): try: - self.file_mimetype, self.mime_encoding = get_document_mimetype(self) + self.file_mimetype, self.mime_encoding = get_mimetype(self.open(), self.get_fullname()) except: self.file_mimetype = u'' self.file_mime_encoding = u'' diff --git a/apps/sources/staging.py b/apps/sources/staging.py index 8a0a200859..b2edd41848 100644 --- a/apps/sources/staging.py +++ b/apps/sources/staging.py @@ -138,6 +138,7 @@ class StagingFile(object): try: return convert(self.filepath, size=size, cleanup_files=False, transformations=transformations) except UnknownFileFormat: - return get_icon_file_path(get_mimetype(self.filepath)) + mimetype, encoding = get_mimetype(open(self.filepath, 'rb'), self.filepath) + return get_icon_file_path(mimetype) except UnkownConvertError: return get_error_icon_file_path()