I have a little problem with my validator code, its saving 0 byte images and I just don't know why, the value variable is an image that actually contains an image, I have tested it several times to see what it contains and its an image but for some reason when it comes to saving it in the database it saves an empty image, please assist me where I could be going wrong. Regards
from gluon import *
import pytesseract
from PIL import Image
class IS_RECEIPT_OR_INVOICE(object):
def __init__(self, error_message="The uploaded file is not a receipt or invoice!"):
self.error_message = error_message
def __call__(self, value):
error = None
try:
image = Image.open(value.file)
text = pytesseract.image_to_string(image)
if "receipt" not in text.lower() and "invoice" not in text.lower() and "RECEIPT" not in text and "INVOICE" not in text:
error = self.error_message
except:
error = self.error_message
return (value, error)