From 6e7af5b449c7f847b759f806f390beb674712181 Mon Sep 17 00:00:00 2001 From: Loic Teixeira Date: Mon, 23 Apr 2018 10:28:11 +1000 Subject: [PATCH] Fix crash when saving an image (#10) --- wagtailenforcer/utilities.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wagtailenforcer/utilities.py b/wagtailenforcer/utilities.py index 7e873b1..a8ac01c 100644 --- a/wagtailenforcer/utilities.py +++ b/wagtailenforcer/utilities.py @@ -9,7 +9,13 @@ def check_for_virus(instance): - has_virus, name = is_infected(instance.file.read()) + if instance.file.closed: + with open(instance.file.path, 'rb') as file: + file_content = file.read() + else: + file_content = file.read() + + has_virus, name = is_infected(file_content) if has_virus: raise EnforcerVirusException(_('Virus "{}" was detected').format(name))