mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-19 01:23:02 +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.observers import Observer
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
|
from django.core.files import File
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -67,16 +68,19 @@ class PDFHandler(FileSystemEventHandler):
|
||||||
|
|
||||||
metadata += text
|
metadata += text
|
||||||
|
|
||||||
document, created = Document.objects.get_or_create(
|
# Open the file for instance creation
|
||||||
|
DOCUMENT, created = Document.objects.get_or_create(
|
||||||
name=filename,
|
name=filename,
|
||||||
defaults={
|
defaults={
|
||||||
'number_pages': num_pages,
|
'number_pages': num_pages,
|
||||||
'ocr_metadata': metadata,
|
'ocr_metadata': metadata,
|
||||||
'document_type': document_type
|
'document_type': document_type
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
|
DOCUMENT.file.save(
|
||||||
|
name=filename, content=File(open(file_path, 'rb')))
|
||||||
self.logger.info(f"Document '{filename}' created successfully with type '{
|
self.logger.info(f"Document '{filename}' created successfully with type '{
|
||||||
document_type}'.")
|
document_type}'.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue