mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-18 17:13:00 +08:00
Fix files not being read properly in watcher
This commit is contained in:
parent
65662aeb45
commit
559baca38c
1 changed files with 6 additions and 2 deletions
|
@ -10,6 +10,7 @@ from config.settings import MEDIA_ROOT
|
|||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from documents.models import Document
|
||||
from django.core.files import File
|
||||
import logging
|
||||
import time
|
||||
|
||||
|
@ -67,16 +68,19 @@ class PDFHandler(FileSystemEventHandler):
|
|||
|
||||
metadata += text
|
||||
|
||||
document, created = Document.objects.get_or_create(
|
||||
# Open the file for instance creation
|
||||
DOCUMENT, created = Document.objects.get_or_create(
|
||||
name=filename,
|
||||
defaults={
|
||||
'number_pages': num_pages,
|
||||
'ocr_metadata': metadata,
|
||||
'document_type': document_type
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
if created:
|
||||
DOCUMENT.file.save(
|
||||
name=filename, content=File(open(file_path, 'rb')))
|
||||
self.logger.info(f"Document '{filename}' created successfully with type '{
|
||||
document_type}'.")
|
||||
|
||||
|
|
Loading…
Reference in a new issue