From e5c488031de2a8e8d2e71385cfc053d7858bd7f5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 9 Aug 2021 22:27:13 +0100 Subject: [PATCH] Remove existing media files if not media is detected within a post --- content.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/content.py b/content.py index b6c631981..23dfc3b3b 100644 --- a/content.py +++ b/content.py @@ -932,6 +932,16 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, Returns the filename and attachment type """ if not mediaBytes: + if filenameBase: + # remove any existing files + extensionTypes = getImageExtensions() + for ex in extensionTypes: + possibleOtherFormat = filenameBase + '.' + ex + if os.path.isfile(possibleOtherFormat): + os.remove(possibleOtherFormat) + if os.path.isfile(filenameBase): + os.remove(filenameBase) + if debug: print('DEBUG: No media found within POST') return None, None