diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index 6e055e46eb..4a1486467e 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -7,6 +7,7 @@ import uuid from django.conf import settings from django.core.files import File +from django.core.files.base import ContentFile from django.db import models, transaction from django.template import Template, Context from django.urls import reverse @@ -858,6 +859,11 @@ class DocumentPage(models.Model): page_image = converter.get_page() + # Since open "wb+" doesn't create files, check if the file + # exists, if not then create it + if not documentimagecache_storage.exists(cache_filename): + documentimagecache_storage.save(name=cache_filename, content=ContentFile(content='')) + with documentimagecache_storage.open(cache_filename, 'wb+') as file_object: file_object.write(page_image.getvalue()) except Exception as exception: